Encryption


UvwmeVpkmuw


Encryption is the process of converting a readable message (sometimes referred to as plaintext) into a form that cannot be read by anyone except the intended receiver.

There are many ways in which encryption can be performed. One of the simplest ways is to merely replace each letter of the message with the letter that is located a fixed distance further down in the alphabet. For example, if we were to replace every letter in the message:

YOU ARE IN GREAT DANGER
with the corresponding letter located three positions further on in the alphabet, we would get:
BRX DUH LQ JUHDW GDQJHU
(Notice that the letter "Y" encrypted into the letter "B", since we can think of the alphabet as "wrapping around" past the letter "Z".) This form of encryption is often called the Caesar Shift Cipher, because Julius Caesar frequently used it in his writings. It was also the basis for the Captain Midnight "Secret Decoder Ring" which was popular in the US around the late 1940s. (Click here to see how you can use your computer to easily create your own Caesar Shift encryptions.)

Because there are only 25 possible ways we can shift the entire alphabet (the 26th brings us back to the beginning again), there are only 25 possible ways that a message can be encrypted by using the Caesar shift method. Such an encrypted message is therefore very easy to break by using a little trial and error.

However there is no need to shift the entire alphabet as if it were a single rigid body. We can allow each letter of the alphabet to shift independently by an amount which we will call delta. For example, we might shift the letter "A" seven places to the right (delta = 7) so that it encrypts into the letter "H", while the letter "B" gets shifted ten places to become an "L", etc. as shown in the partial table below:

        Plaintext letter: A  B  C  D  E  F  G . . .  X  Y  Z

Encrypted letter: H L K Q J F W . . . M P B

Delta: 7 10 8 13 5 0 16 . . . 15 17 2

If we allow the possibility that any letter may uniquely encrypt into any letter, we find that there are 26! possible ways to encrypt any given message. (The number 26! is greater than 400,000,000,000,000,000,000,000,000.)

While it may seem that 26! possibilities would make such a code almost impossible to break, experts can (and do) crack such codes quite easily. And that's because the method still suffers from a fundamental design flaw -- Any given letter of the plaintext message always generates the same fixed letter in the encrypted message.

A better way to encrypt a message is to generate a random delta value for each letter's location in the plaintext message. For example, let's suppose our random number generator produces the following sequence of random delta values:

  2 0 7 -3 1 -5 4 -2

Then the plaintext message:

I LOVE YOU

would encrypt into:

K LVSF TSS

because: "I" + 2 = "K", "L" + 0 = "L", "O" + 7 = "V", etc.

(We have used the symbol "+" to mean "shift".) Notice that the "O" in the word "LOVE" became a "V", while the "O" in the word "YOU" now became a different letter ("S").

"But, wait a minute," you're probably thinking. "If we've just encrypted our plaintext message by shifting each letter into a new random letter, how in the world will anybody (including the intended receiver) ever be able to decrypt it?"

Easy! As you recall, the computer's random number generator does not generate truly random numbers. If you write a program to display a sequence of random numbers, and then run that program over and over, you will always get the same sequence of "random" numbers (assuming, of course, that you haven't invoked the "randomize" task). And anybody else who runs your program on their own computer will also get the very same sequence. Therefore, the receiver of your encrypted message can easily decode it. All he has to do is generate the same sequence of "random" numbers that you used, and then use each of those numbers to unshift the corresponding letters of the encrypted message.

To illustrate, let's write a short SiMPLE program that will encrypt the message, "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS", by shifting each letter a random amount:

t = "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS"
Do k = 0, length(t)-1
   char = extract(t, k, k)
   aschar = ascii(char)
   If aschar >= ascii("A") And aschar <= ascii("Z")
      delta = random(26)
      aschar = cycle(aschar-ascii("A")+delta, 26) //Positive delta!
      char = char(aschar+ascii("A"))
   Endif
   Display char,
Loop k

When you run the program, it produces the following encrypted output:

THM QDNPP TPVHP XCY NPDIZB TGCM RCP AROM VQQV

To decrypt the message, all we have to do is subtract the very same random delta (in line 7) that was used to encrypt the message:

t = "THM QDNPP TPVHP XCY NPDIZB TGCM RCP AROM VQQV"
Do k = 0, length(t)-1
   char = extract(t, k, k)
   aschar = ascii(char)
   If aschar >= ascii("A") And aschar <= ascii("Z")
      delta = random(26)
      aschar = cycle(aschar-ascii("A")-delta, 26) //Negative delta!
      char = char(aschar+ascii("A"))
   Endif
   Display char,
Loop k

And, Presto!, the original message reappears:

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOGS



  [ Webmaster | FAQ's | Home Page | Contact Us ]