02-21-2010, 07:14 PM
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;
}
?>