Michdd Posted November 5, 2008 Share Posted November 5, 2008 How could I make a simple encryption that would encrypt a string, but I could decrypt it back with a different script. Link to comment https://forums.phpfreaks.com/topic/131444-solved-simple-encryptiondecryption/ Share on other sites More sharing options...
blueman378 Posted November 5, 2008 Share Posted November 5, 2008 it really depends on you. i mean if you really wanted you could do something simple like assign a=1 b=2 ect then count the string length add that onto each number and then change the string to the numbers. decrypt it by reversing lol Link to comment https://forums.phpfreaks.com/topic/131444-solved-simple-encryptiondecryption/#findComment-682653 Share on other sites More sharing options...
corbin Posted November 5, 2008 Share Posted November 5, 2008 Think if encryption as a function, and think of decrypting as the inverse of said function. For example, if f(1) = 3, then f^-1(3) should = 1. (f^-1 meaning opposite of f.) So, you'll essentially need to come up with something that can be reversed, but not done so easily. You could use a key to encrypt it against, or you could just change the value or what ever. Or, you could use some of the algorithms already out there. Link to comment https://forums.phpfreaks.com/topic/131444-solved-simple-encryptiondecryption/#findComment-682654 Share on other sites More sharing options...
Michdd Posted November 5, 2008 Author Share Posted November 5, 2008 it really depends on you. i mean if you really wanted you could do something simple like assign a=1 b=2 ect then count the string length add that onto each number and then change the string to the numbers. decrypt it by reversing lol How could I make something that would change all, for example, a's to 3, within a certain string? Link to comment https://forums.phpfreaks.com/topic/131444-solved-simple-encryptiondecryption/#findComment-682655 Share on other sites More sharing options...
blueman378 Posted November 5, 2008 Share Posted November 5, 2008 regex Link to comment https://forums.phpfreaks.com/topic/131444-solved-simple-encryptiondecryption/#findComment-682663 Share on other sites More sharing options...
blueman378 Posted November 5, 2008 Share Posted November 5, 2008 it really depends on you. i mean if you really wanted you could do something simple like assign a=1 b=2 ect then count the string length add that onto each number and then change the string to the numbers. decrypt it by reversing lol How could I make something that would change all, for example, a's to 3, within a certain string? regex Link to comment https://forums.phpfreaks.com/topic/131444-solved-simple-encryptiondecryption/#findComment-682664 Share on other sites More sharing options...
DarkWater Posted November 5, 2008 Share Posted November 5, 2008 Horrid ideas. >_> Just use simple XOR encryption. I wrote up a quick set of functions for you: <?php function xor_crypt($input, $key) { $input_l = strlen($input); $key_l = strlen($key); for ($i=0;$i<$input_l;$i++) { $pos = $i % $key_l; $input[$i] = chr(ord($input[$i]) ^ ord($key[$pos])); } return $input; } function do_encrypt($input, $key) { $input = xor_crypt($input, $key); $input = base64_encode($input); return $input; } function do_decrypt($input, $key) { $input = base64_decode($input); $input = xor_crypt($input, $key); return $input; } Usage: <?php $string = "JUST some RANDOM string going on here.... >_>"; $key = "ASHD77278qu389*A*S*D0a)))(ASdjuio!$^$RHF"; $enc = do_encrypt($string, $key); echo "$enc\n"; echo do_decrypt($enc, $key) . "\n"; Link to comment https://forums.phpfreaks.com/topic/131444-solved-simple-encryptiondecryption/#findComment-682665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.