Crew-Portal Posted September 13, 2009 Share Posted September 13, 2009 Quick question about encription. Is there a way of encoding information and then having a relable way of decoding it? Preferable with a easter egg. Such as: $encoded_string = "Testing".$secretword; I tried using base64_encode and _decode, and it worked perfectly. The only problem is that the string length is not constant. I need a way of encoding so that the length is always the same.. 4 Charactors.. 50 Charactors. It doesnt matter, It just has to be constant. So that "test" and "Hello my name is billy bob joe" Would both encode with a str length of like.. 18. You know what I mean? Quote Link to comment https://forums.phpfreaks.com/topic/174109-solved-md5-base64_encode-help/ Share on other sites More sharing options...
Mark Baker Posted September 13, 2009 Share Posted September 13, 2009 So you're after a method of encoding data where the single character string "A" and a 10MB binary document would both encrypt to the same size. Such a creature doesn't exist, for pretty obvious reasons. But can you explain exactly why you think you need this? Quote Link to comment https://forums.phpfreaks.com/topic/174109-solved-md5-base64_encode-help/#findComment-917777 Share on other sites More sharing options...
phporcaffeine Posted September 13, 2009 Share Posted September 13, 2009 I'm not sure what your trying to do either but this is an example of basic XOR and base_64 encryption: <?php function XOREncryption($InputString, $KeyPhrase){ $KeyPhraseLength = strlen($KeyPhrase); // Loop trough input string for ($i = 0; $i < strlen($InputString); $i++){ // Get key phrase character position $rPos = $i % $KeyPhraseLength; // Magic happens here: $r = ord($InputString[$i]) ^ ord($KeyPhrase[$rPos]); // Replace characters $InputString[$i] = chr($r); } return $InputString; } //SALT $salt = 'my_special_phrase'; //ENCRYPT $crypted = XOREncryption('my string', $salt); //DECRYPT $decrypted = XOREncryption($crypted, $salt); ?> Quote Link to comment https://forums.phpfreaks.com/topic/174109-solved-md5-base64_encode-help/#findComment-917805 Share on other sites More sharing options...
Crew-Portal Posted September 13, 2009 Author Share Posted September 13, 2009 That works great phpORcaffine. But why cant I echo $crypted? Quote Link to comment https://forums.phpfreaks.com/topic/174109-solved-md5-base64_encode-help/#findComment-917818 Share on other sites More sharing options...
phporcaffeine Posted September 13, 2009 Share Posted September 13, 2009 Try this one .... I pulled the function out of some code that I was building and my head was in 5 different spots ... I didn't get it all. Here you go: <?php function XOREncryption($InputString, $KeyPhrase){ $KeyPhraseLength = strlen($KeyPhrase); // Loop trough input string for ($i = 0; $i < strlen($InputString); $i++){ // Get key phrase character position $rPos = $i % $KeyPhraseLength; // Magic happens here: $r = ord($InputString[$i]) ^ ord($KeyPhrase[$rPos]); // Replace characters $InputString[$i] = chr($r); } return $InputString; } //SALT $salt = 'my_special_phrase'; //ENCRYPT $crypted = base64_encode(XOREncryption('my string', $salt)); echo "Encrypted: " . $crypted . "<br />"; //DECRYPT $decrypted = XOREncryption(base64_decode($crypted), $salt); echo "Decrypted: " . $decrypted; ?> Quote Link to comment https://forums.phpfreaks.com/topic/174109-solved-md5-base64_encode-help/#findComment-917824 Share on other sites More sharing options...
Crew-Portal Posted September 13, 2009 Author Share Posted September 13, 2009 Beautiful. Thanks alot man Quote Link to comment https://forums.phpfreaks.com/topic/174109-solved-md5-base64_encode-help/#findComment-917826 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.