Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

My ENIGMAtic Java Ring

Using the model of an old wartime encryption machine, find out how to fashion your own secret encoder ring

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

Page 3 of 6

There are two kinds of simple substitution ciphers, algorithmic and mapping.

Algorithmic substitution cipher
In an algorithmic substitution cipher the "key" to the cipher is the algorithm. For example, an algorithmic cipher that has the key "Add 3" would operate as follows:

  • For each letter in the input message, substitute the letter that is three more letters along in the alphabet

  • If the letter is X, Y, or Z, then substitute the letters A, B, and C respectively


When the above cipher is used, the input message, HELLO BOB (this is called the message text) would be translated into the output message KHOOR ERE (called the cipher text). Unfortunately, algorithmic ciphers are pretty easy to decode even without the key, as there are very common letter patterns in the English language. Further, the "rules" associated with English spelling (such as the necessity of having a vowel in every word) and certain common single-character words make the letter relationships fairly apparent. To obscure the obvious relationship of the letters in the output message to the letters in the input message, the output message was often reformatted in a fixed pattern of character groups. Thus the output KHOOR ERE would be reformatted using four-letter groups to be KHOO RERE. The reformatting makes it less obvious where the words begin and end, but it means that the clerk decoding the message has to read it to figure out where to reinsert the spaces.

Another problem with algorithmic ciphers is their construction. The construction of an algorithmic substitution cipher requires that the key be just one algorithm. Once that algorithm is known for one letter, it's known for all letters. This can be used by an adept cryptanalyst who first counts all of the letters in the cipher text, notes the most commonly occurring letter, combines this with the knowledge that the letter E is the most commonly occurring letter in the English language, and then figures out through deduction what the relationship is between the most common character in the cipher text and the letter E. In short order, the algorithm is known and the cipher is broken. The message is then easily decoded.

Mapping substitution cipher
This brings me to the other type of substitution cipher, the mapping cipher. In a mapping cipher, a fixed relationship exists between input characters and output characters, but that relationship is held by a translation table rather than by using an algorithm. For example, let us assume your alphabet consisted of exactly seven letters -- A, B, C, D, E, F, and G -- and you set up a translation table as shown below.



Input character A B C D E F G
Output character B G E D F C A
Table 1: Character substitution map


If you were to use the message text CAFE BABE and substitute the letters from the table, you would get the cipher text EBCF GBGF. This doesn't look all that different from the algorithmic cipher -- until the cryptanalyst tries to break the code. The advantage of using the table is that while the analyst could find the relationship between the message text letter E and the cipher text letter F using the same statistical method that I described above, that information wouldn't tell her the relationship between the message text letter B and the cipher text letter G. This property, the independence of the relationship between the letters of the message and the encrypted message, makes the mapping cipher stronger -- in the sense that it's harder to break than the algorithmic cipher.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • Enigma.java is the ENIGMA applet http://www.javaworld.com/jw-08-1998/indepth/Enigma.java
  • Rotor.java is the implementation of an ENIGMA rotor http://www.javaworld.com/jw-08-1998/indepth/Rotor.java
  • Home page for the Dallas Semiconductor iButton http://www.ibutton.com
  • Pictures of the ENIGMA machine http://www.math.arizona.edu/~dsl/ephotos.htm
  • More pictures of the ENIGMA machine http://cs.oberlin.edu/classes/cs115/lect30n.html
  • A nice description of the ENIGMA machine http://www.math.arizona.edu/~dsl/enigma.htm
  • Another good description of the ENIGMA machine http://www.trincoll.edu/~cpsc/cryptography/enigma.html
  • Java applet that emulates the ENIGMA machine http://www.attlabs.att.co.uk/andyc/enigma/enigma_j.html
  • Patent for the ENIGMA machine http://www.patents.ibm.com/details?patent_number=3984922
  • Breaking the ENIGMA algorithm and decrypting messages that are ENIGMA encrypted http://www.cs.miami.edu/~harald/enigma/enigma.html
  • A description of many modern cryptographic algorithms http://www.mach5.com/crypto/algorithms.html
  • Previous Java In Depth articles http://www.javaworld.com/topicalindex/jw-ti-indepth.html