I am really curious about it, Actually I wanna know what is the most efficient way to achieve it in php.
For example Convert ThisIsASampleText to dhiandt47hes8 which every letter of the first relates to the second.
My important goal is speed.
-
This is a cryptographic full algorithm. stackoverflow.com/questions/25555011/…sugunan– sugunan2014-09-14 15:49:50 +00:00Commented Sep 14, 2014 at 15:49
Add a comment
|
1 Answer
This should work:
// define encoding, make sure every character is unique
$STRAIGHT = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
$GARBLED = ')OCD[89nopH#JK{Mab%de?fgUVWq*stPQ!x(z01EFh]j}lm$623.RSTGXYZABuvw4';
// test
$str = 'ThisIsASampleText';
// encode
$encoded = strtr($str,$STRAIGHT,$GARBLED);
echo $encoded.'<br>';
// decode
$str = strtr($encoded,$GARBLED,$STRAIGHT);
echo $str;
Make sure all the characters you need are in the definition string. I'm not sure whether there's a faster solution, but this is very simple. DO NOT USE to secure data, it's far to simple for that.
2 Comments
UltraDEVV
Why not use to secure data? Could you suggest a way to secure data?
KIKO Software
As I said, and you can see, it's too simple. This is the most basic type of encoding anybody can think of. You should write another question if you want suggestions on how to securely encrypt data. You cannot change your original question in a comment.