Exclusive OR Encryption

Authors

Publication

Pub Details

Date

Pages

See all articles from QL Hacker's Journal 26

I’ve always been interested in encryption. Keeping my files safe from prying eyes has been more of a want than a need. Plus encryption is a neat programming problem to solve. Many years ago I wrote a program called QL Crypt that was my first look at encryption. In QHJ #XX there was Complex Ascii Rotation (CAR) that was aimed at encrypting mail messages just enough to make them secure from casual observers. There are many other ways to encrypt files, each with it’s own level of safety.

Encryption is based on two parts, the Method and the Key. The Method is what various computations are performed to get from the clear text to the encrypted text. This is equivalent to a lock. The Key is the chunk of data used to make one encryption different than an other. Since the encryption Method does not change, it is the Key that makes your text encrypted different from somebody else’s. This is the equivalent to, well, a key. A specific model of lock is manufactured into a thousands of individual locks. These locks all look and work the same. It is the key that makes each one secure and different from the others.

There are many methods used in encryption, from the very easy to break, to the damn near impossible. The harder to break, the more computation necessary to encrypt. If you are worried about wasting computational cycles, then you need only implement the Method that secures the information to the level you need it. Securing a Christmas gift list is different than securing company trade secrets.

QL Crypt and CAR both used a character rotation Method for encryption. As each character was read in, a value of 1-4 would be added to their character value (CHR$), based on the Key, and then output to the resultant file. QL Crypt allowed the encryption of binary files, CAR stayed with pure ASCII text so that it could be sent in e-mail.

Each one of these Methods, and many more, require the use of two functions that are the opposite of each other. In character rotation, a value would be added to encrypt, and subtracted to decrypt. What ever gyrations you go through to encrypt you must reverse to decrypt. Exclusive OR encryption does not have two opposite functions because Exclusive OR is the opposite of itself.

Exclusive OR (XOR)

      Bit 1  Bit 2     XOR
0 0 0
1 0 1
0 1 1
1 1 0

When using Exclusive OR with a bit pattern, what you XOR it with is usually called the Mask. To show you how XOR is the opposite of itself let take a look at the binary pattern 010110 XORed with the mask 111111.

       Bit   Mask    XOR          Bit   Mask    XOR
0 1 1 1 1 0
1 1 0 0 1 1
0 1 1 1 1 0
1 1 0 0 1 1
1 1 0 0 1 1
0 1 1 1 1 0

Notice that after XORing the bit pattern with the mask and then XORing the resultant bit pattern with the mask the original bit pattern returns. This means that writing the program to implement XOR encryption does not require the writing of an encryption routine and a decryption routine, only one is XOR routine is needed.

The Mask that is used in the XOR routine is derived from the Key. How secure you data is, is dependent on the Key and its length. If you use a Key of length one (1 byte) then it would take only 256 tries to break the encryption. The longer the Key, the more tries necessary to break the encryption.

QL Crypt used the random number table in the QL as the key. A password was entered from the user, which then was used as the sed value for the random number table. This makes for very strong encryption (as the random number table is fairly large and makes a long Key), but it make it impossible to port to other platforms. Even differences in QL ROMs could cause the program to fail.

CAR used a ASCII password entered by the user. This makes the program very portable, but also makes it a weaker form of encryption. If the user typed in a fairly long password, then the level of secureness would go up.

Products

 

Downloadable Media

 

Image Gallery

Scroll to Top