Support Forums
[Function] XOR Encryption/Decryption with a Key - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: [Function] XOR Encryption/Decryption with a Key (/showthread.php?tid=4941)



[Function] XOR Encryption/Decryption with a Key - OX!DE - 02-21-2010

Another function coded by me to encrypt/decrypt a string using a key.

PHP Code:
<?php
// Example Usage: echo xorencrypt('examplestring,'examplekey');
function XOREncryption($InputString$KeyPhrase){
$KeyPhraseLength strlen($KeyPhrase);
for (
$i 0$i strlen($InputString); $i++){
$rPos $i $KeyPhraseLength;
$r ord($InputString[$i]) ^ ord($KeyPhrase[$rPos]);
$InputString[$i] = chr($r);
}
return 
$InputString;
}
function 
xorencrypt($InputString$KeyPhrase){
    
$InputString XOREncryption($InputString$KeyPhrase);
    
$InputString base64_encode($InputString);
    return 
$InputString;
}
function 
xordecrypt($InputString$KeyPhrase){
    
$InputString base64_decode($InputString);
    
$InputString XOREncryption($InputString$KeyPhrase);
    return 
$InputString;
}
?>