This is not about security. It is also not to make it hard to break. I'm looking for a simple algorithm to change a string (a url) in a way it does not resemble the original. The encryption will be done with javascript. Then I want to feed the encrypted string to a PHP function to change it back to the original. Both ends could share a secret key, or the conversions could be key-less and rely on just logic.
The ideal solution
- will be simple
- will use available javascript functions for encryption
- will use available php functions for decryption
- will produce encrypted string in way not to resemble the plain text at all
- will only use lower-case alphabet characters and numbers in the encrypted string
- is not a method widely used like Base64-ing as encryption.
Edit: The last requirement was added after shamittomar's answer.
How are you planning to implement (hide) the secret in Javascript? IMHO it's not possible.
Edit: OK - not about security.. then just use any baseXX or rot encoding mechanism. But you can't really say one of these algorythms would not be well known...
If that's what you want, you can Base64 encode and decode that.
[EDIT]: After OP clarification:
As you do not want widely used methods, here is one rarely used method and that can do it for you by giving output only in LOWERCASE letters and NUMBERS. It is Base32 Encode/Decode. Use the following libraries:
If it's not about security, and not about making it hard to break, then how about
ROT-13
?PHP has a native function,
str_rot13
: http://php.net/manual/en/function.str-rot13.phpYou can use bitwise XOR in javascript to encode the string and again in PHP to decode it again. I wrote a little Javascript example for you. It works the same in PHP. If you call enc() a second time with the already encoded string, you'll get the original string again.
In PHP do something like this (caution, this is not tested and it's been a long while since I did PHP):
Well I found this page and found Redcully's program not work for me so I thought It happens with all others. finally I got reason and fixed it. Here new code is... Thanks to Redcully :)
JS function:
PHP function: