Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1013855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:10:04+00:00 2026-05-16T10:10:04+00:00

Given an input string (will actually be an integer value) and an encryption key,

  • 0

Given an input string (will actually be an integer value) and an encryption key, I need to encrypt the input string in such a way that the resulting string is:

  1. URL safe (my permitted URI characters is currently: a-z 0-9~%.:_-)
  2. Filename safe (meaning, it only uses valid directory/filename characters)
  3. FTP account username safe
  4. Email account username safe

Then, given the encrypted string and the same encryption key, decrypt the the string into its unencrypted form.

This is not intended to be a security measure. Implementation needs to be in PHP. Thanks.

EDIT 1 (the decoding still includes undesirable characters; plus, there is no way to make sure the resulting encrypted string is within a certain length):

function decrypt($string, $encryption_key)
{
    assert(isset($string) === TRUE);
    assert(isset($encryption_key) === TRUE);

    $result = '';
    $string = base64_decode($string);

    for ($i = 0; $i < strlen($string); $i++)
    {
        $char    = substr($string, $i, 1);
        $keychar = substr($encryption_key, ($i % strlen($encryption_key)) - 1, 1);
        $char    = chr(ord($char) - ord($keychar));
        $result .= $char;
    }

    return $result;
}


function encrypt($string, $encryption_key)
{
    assert(isset($string) === TRUE);
    assert(isset($encryption_key) === TRUE);

    $string = (string) $string;
    $result = '';

    for ($i = 0; $i < strlen($string); $i++)
    {
        $char    = substr($string, $i, 1);
        $keychar = substr($encryption_key, ($i % strlen($encryption_key)) - 1, 1);
        $char    = chr(ord($char) + ord($keychar));
        $result .= $char;
    }

    return base64_encode($result);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:10:04+00:00Added an answer on May 16, 2026 at 10:10 am

    Consider encryption and encoding as two distinct and unrelated steps. In one direction you encrypt plaintext bytes to get cipher bytes, then encode the bytes to get a string. The other direction you decode the string to get ciphertext bytes, then decrypt the ciphertext bytes to get plaintext bytes.

    Your requirements can be most simply satisfied by using a simple hex, or base 16, encoder that converts a byte into two hex characters. If encoding space efficiency is absolutely critical, you can implement your own base-62 encoder that uses only upper and lower case letters and digits. It will be slower and possibly uglier than hex encoding.

    EDIT 1:

    If base-64 encoding produces acceptable strings all the better. Base-64 uses 4 characters to encode 3 bytes. So if you are limited to 64 characters then you cannot encode more than (64/4) * 3 = 48 bytes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given that an input String may be specified as follows: read(xpath(‘...’)) or xpath(‘...’) or
Given a user input string, I need to find if it end with one
So given this input string: =?ISO-8859-1?Q?TEST=2C_This_Is_A_Test_of_Some_Encoding=AE?= And this function: private string DecodeSubject(string input) {
I need to retrieve a regex pattern matched strings from the given input. Lets
Given an input sequence, what is the best way to find the longest (not
Given a list L of n character strings, and an input character string S,
The task I was trying to accomplish was that given an input pattern, e.g.
I noticed that when I store a double value such as e.g. x =
Given an input string: <m>1</m> <m>2</m> <m>10</m> <m>11</m> I would like to replace all
Here is the problem: Remove specified characters from a given string. Input: The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.