-1

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.

1

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Why not use to secure data? Could you suggest a way to secure data?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.