My ENIGMAtic Java Ring

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

1 2 3 4 Page 4
Page 4 of 4

The error method would take an error number and return a five-character string of the form "Exxxx" where xxxx was replaced with the error number. I could then use error numbers like 0x1000 to 0x1ffff for initialization, 0x2000 to 0x2fff for method invocations, and so on. This code gave me a way to communicate back to myself as to where I had arrived in the execution of the ring applet.

I then began to throw in invocations of the error method to see how far my code had progressed before it hung. I determined that the ISOExceptions were a source of trouble, so I removed them in favor of invocations of my error method. Then I discovered that the results of the encryption were always wrong, and that led me to find out that the initializer in Rotor was not being called. Finally, after all this, I got my first successful encryption and decryption and raised quite a cheer.

Using the Enigma applet

Once you've successfully loaded the Enigma applet, you can use it with the apduSender application. In the future I'll write a nicer client applet to talk to the Enigma applet.

The first step is to select the applet. To select the Enigma applet, you use the Select option in the apduSender application. When the application prompts for the applet to select, enter the string Enigma.

Next, set the key. This can be done by either setting a new key, or resetting the Enigma to the previously set key. To set a new key in the apduSender application, use the process option to bring up a screen that has a form containing the parts of an APDU. Fill in the Class byte with 85 and the Instruction byte with 01. To set a new key in the text box, type in a three-character string. To reset the key to the last key set, fill in the Class byte with 85 and the Instruction byte with 02.

Finally, to encrypt a message, use the process command of apduSender and set the Class byte to 85 and the Instruction byte to 03. Type in the message to encrypt as a string in the text box. Remember that this is a BASE64 string, so you have a limited character set available. Uppercase and lowercase characters are available, but space is not. My first test message was HelloWorld. You'll notice that it takes a bit of time to encrypt the message.

Decrypting a message is identical to encrypting one: select the applet, set or reset the key, and type in the encrypted message. The decrypted message will be output as the result.

Wrapping up

The Java Ring makes an excellent host for my ENIGMA simulation classes. With the ENIGMA classes, this high-tech equivalent of a secret decoder ring is capable of encrypting and decrypting "secret" messages. Further, the ENIGMA algorithm is strong enough that it can't be casually cryptanalyzed. And the key used to encrypt and decrypt the messages never needs to leave the ring, which adds a good deal of security to the system.

This project also served as the motivation I needed to sit down and really program the ring. I find I rarely learn systems well until I use them to accomplish some task.

As I mentioned at the beginning of the article, the ENIGMA algorithm is no longer considered to be weapons grade cryptography. It does provide a good introduction to cryptography, however, and should be studied as part of any serious effort to learn about cryptographic systems. When the next version of the iButton is released, it's expected to support the built-in RSA crypto hardware, which will enable the ring to use much stronger algorithms.

The algorithm I've used can be strengthened by increasing the number of rotors, and by making the rotor material downloadable. Because the definition of the "keying material" for any encryption system includes any data that can be changed from one use of the system to the next, if you do decide to modify the Enigma class to make the rotor data downloadable, the rotor data effectively becomes part of the key itself. If you read the paper referenced below on the efforts to decrypt ENIGMA messages, however, you will see that the simple substitution aspects of the algorithm doomed it to eventual failure. Modern cryptographic systems such as DES, IDEA, and Blowfish are entirely algorithm-based, using mathematical techniques to effectively scramble the data and hide it from prying eyes.

If you have a Java Ring, I encourage you to try out this applet and take the time to understand and modify it. This will give you a better feel for what these rings can and cannot do. Of course, a piece of jewelry that doubles as a privacy protector is also a great conversation piece. In future columns I'll be looking at other applications of the Java Card technology and will design a couple of user interfaces as well.

Chuck McManis currently is a distinguished engineer at FreeGate Corp., a venture-funded startup that is exploring opportunities in the Internet marketplace. Before joining FreeGate, Chuck was a member of the Java Group. He joined the Java Group just after the formation of FirstPerson Inc. and was a member of the portable OS group (the group responsible for the OS portion of Java). Later, when FirstPerson was dissolved, he stayed with the group through the development of the alpha and beta versions of the Java platform. He created the first "all-Java" home page on the Internet when he did the programming for the Java version of the Sun home page in May 1995. He also developed a cryptographic library for Java and versions of the Java class loader that could screen classes based on digital signatures. Before joining FirstPerson, Chuck worked in the operating systems area of SunSoft, developing networking applications. There, he did the initial design of NIS+. Check out his home page.

Learn more about this topic

  • 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
1 2 3 4 Page 4
Page 4 of 4