Master, a reversible string encryption algorithm

Source: Internet
Author: User
Requires support for Chinese characters (non-rigid requirements), alphanumeric, decimal, etc., the encrypted string consists of numbers and characters, preferably encrypted and before the length of the encryption
such as the "Www.qq.com" string before encryption


Reply to discussion (solution)

The same can be considered the replacement algorithm, the simplest, the substitution rules can be defined by themselves,

The same can be considered the replacement algorithm, the simplest of the substitution rules can be defined by themselves, there is code

If you don't think about Chinese characters, just use Caesar to encrypt it.

$s = ' www.qq.com~ '; $k = 13;//encryption for ($i =0; $i
 
  126) $n = ($n + +) & 0x7f; $s {$i} = Chr ($n);} Echo $s, php_eol; $$$;~~;p |z+//decryption for ($i =0; $i
   
   

If you don't think about Chinese characters, just use Caesar to encrypt it.

$s = ' www.qq.com~ '; $k = 13;//encryption for ($i =0; $i
    
     126) $n = ($n + +) & 0x7f; $s {$i} = Chr ($n);} Echo $s, php_eol; $$$;~~;p |z+//decryption for ($i =0; $i
       
      

This method is good, but did not meet my requirements, that is, the encrypted string can only have numbers, letters

If you don't think about Chinese characters, just use Caesar to encrypt it.

$s = ' www.qq.com~ '; $k = 13;//encryption for ($i =0; $i
       
        126) $n = ($n + +) & 0x7f; $s {$i} = Chr ($n);} Echo $s, php_eol; $$$;~~;p |z+//decryption for ($i =0; $i
          
         

Like ' abcdefghijklmnopqrstuvwxyz1234567890_-. ' After the string is encrypted, it can only be made up of strings and numbers 、-、 _, and the decimal point is converted to other

If I'm not mistaken, your request is, "the encrypted string is made up of numbers and characters."
I don't know what the character is.

Put a character beyond the alphanumeric range to be an alphanumeric representation, or change the length
"Put the elephant in the freezer" is just a joke, you are serious?

Generate string only alphanumeric words, according to your red letter part of the conditions, it is impossible to achieve the blue character requirements

Requires support for Chinese characters (non-rigid requirements), alphanumeric, decimal, etc., the encrypted string consists of numbers and characters, preferably encrypted and before the length of the encryption
such as the "Www.qq.com" string before encryption

Put a character beyond the alphanumeric range to be an alphanumeric representation, or change the length
"Put the elephant in the freezer" is just a joke, you are serious?

Base64 will not be able to "abcdefghijklmnopqrstuvwxyz1234567890_-." Converted to pure numbers and letters? Even if it's a little bit longer, it's just that it feels base64 too long.

Generate string only alphanumeric words, according to your red letter part of the conditions, it is impossible to achieve the blue character requirements


Requires support for Chinese characters (non-rigid requirements), alphanumeric, decimal, etc., the encrypted string consists of numbers and characters, preferably encrypted and before the length of the encryption
such as the "Www.qq.com" string before encryption

It can be a little longer.

You know the bit knowledge of the byte base64 is the limit of visual non-compression encryption
If you want to shorten it, you can use a compression algorithm.


Put a character beyond the alphanumeric range to be an alphanumeric representation, or change the length
"Put the elephant in the freezer" is just a joke, you are serious?

Base64 will not be able to "abcdefghijklmnopqrstuvwxyz1234567890_-." Converted to pure numbers and letters? Even if it's a little bit longer, it's just that it feels base64 too long.

A byte can only represent 256 states
All compression algorithms store consecutive identical fragments in the form of: Count + Fragment
So compression doesn't always reduce the size of the

Base64 converted also with/and =
To be replaced with-_
But Base64 can convert any data, such as Chinese characters, every 3 characters 4, 1/3 longer. It is estimated that the landlord is too wasteful.

It should be changed to convert only the specified characters.
At least be able to convert a-za-z0-9-_. A total of 65 legal characters.
And the output cannot take a point. A total of 64 legal characters, in theory, will grow at least 1/64.

Base64 converted also with/and =
To be replaced with-_
But Base64 can convert any data, such as Chinese characters, every 3 characters 4, 1/3 longer. It is estimated that the landlord is too wasteful.

It should be changed to convert only the specified characters.
At least be able to convert a-za-z0-9-_. A total of 65 legal characters.
And the output cannot take a point. A total of 64 legal characters, in theory, will grow at least 1/64. Theoretically, 1/64 can also be used to find algorithms

The shift algorithm can achieve

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.