 [Home][FAQ Details]

# Encryption - Simple XOR

As we move into the land of Nod and computer programming, we discover techniques for encryption and decryption that are based on doing things with binary numbers. The Simple XOR code performs operations on the binary representations of numbers - which could, of course, represent characters. Some of these systems are touted as "almost as good" as RSA. And they often have 32 byte passwords that would take trillions of years to crack. While it is true that it would take an eternity to check every password, there are other ways to resolve the Simple XOR that can be accomplished in seconds on a computer.

XOR has the following properties:

So the same algorithm can be used to crypt and decrypt our code. Simple XOR is the modern person's VignenËre. It also has the following property:

## Demonstration of Simple XOR

The following code demonstrates using Simple XOR for encryption and decryption. The encoded text is in bytes.

### Text to Encode (or Decoded Text)<script language="javascript"> <!--// function encrypt(s,pw) { var a=0; var myString=''; var textLen=s.length; var pwLen=pw.length; for (i=0;i<textLen;i++) { a=parseInt(s.charCodeAt(i)); a=a^(pw.charCodeAt(i%pwLen)); a=a+""; while (a.length<3) a='0'+a; myString+=a; } form1.tdecrypt.value=myString; } function decrypt(s,pw){ var myString=''; var a=0; var pwLen=pw.length; var textLen=s.length; var i=0; var myHolder=""; while(i<s.length-2) { myHolder=s.charAt(i)+s.charAt(i+1)+s.charAt(i+2); if (s.charAt(i)=='0') { myHolder=s.charAt(i+1)+s.charAt(i+2); } if ((s.charAt(i)=='0')&&(s.charAt(i+1)=='0')) { myHolder=s.charAt(i+2); } a=parseInt(myHolder); a=a^(pw.charCodeAt(i/3%pwLen)); myString+=String.fromCharCode(a); i+=3; }//end of while i form1.tencrypt.value=myString; } //--> </script> Password Text to Decode (or Encoded Text)

The Simple XOR ciphertext is easy to unravel. According to Schneier, it can be achieved in seconds on a computer. The unauthorised decoder first determines the password length (perhaps using mathematical techniques) and then guesses a word in the text. The XOR has the property that when the coded text is XORed with the plain text, it reveals the password.