1. <?php
  2. /**
  3.  * XOR Encryption Functions
  4.  * Created by: Joshua H. (TRUSTAbyss)
  5.  *
  6.  * Usage: xor_encrypt(string, key) to Encrypt the string
  7.  * or xor_decrypt(string, key) to decrypt the string.
  8.  */
  9.  
  10. function xor_encrypt($string, $key)
  11. {
  12. for ($a=0; $a < strlen($string); $a++)
  13. {
  14. for ($b=0; $b < strlen($key); $b++)
  15. {
  16. $string[$a] = $string[$a]^$key[$b];
  17. }
  18. }
  19.  
  20. return $string;
  21. }
  22.  
  23. function xor_decrypt($string, $key)
  24. {
  25. for ($a=0; $a < strlen($string); $a++)
  26. {
  27. for ($b=0; $b < strlen($key); $b++)
  28. {
  29. $string[$a] = $key[$b]^$string[$a];
  30. }
  31. }
  32.  
  33. return $string;
  34. }
  35.  
  36. // Here's an example on using these functions.
  37. //
  38. // Use the name of the key to decrypt the string that was encrypted, using
  39. // the xor_decrypt() function.
  40.  
  41. echo xor_encrypt("I'm going to be encrypted!", "keyName");
  42. ?>