This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programming Diversions and the fly likes Crypto Challenge Instructions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Crypto Challenge Instructions" Watch "Crypto Challenge Instructions" New topic
Author

Crypto Challenge Instructions

Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Seeing how many of us look forward to Angela's daily riddles, I thought I would ride on her coat tails and provide an occasional crypto challenge. If these go over well, I will continue posting them. If not, c'est la vie. Warning in advance, these are not easy.
There are a few components we need to understand in order to solve these things.
First we have the cipher text. This is what you will be trying to decrypt. For example: sghr hr z sdrs.
In order to decrypt this we need to discover the cipher, or what was used to encrypt the message. For example: abcdefghijklmnopqrstuvwxyz. Yes that is the standard alphabet, but it could also be the cipher.
Knowing the cipher is by no means enough. In order to encrypt a message, a cipher is often applied against itself, but shifted by some number. We can call this the offset cipher and the number by which it is shifted we will call the offset.
cipher: abcdefghijklmnopqrstuvwxyz
offset cipher (+1): zabcdefghijklmnopqrstuvwxy
In order to decrypt a message, simply find the letter in the offset cipher, and look up to the same position on the cipher in order to get the plain text letter. The entire decrypted message is refered to as the plain text.
cipher: abcdefghijklmnopqrstuvwxyz
offset: zabcdefghijklmnopqrstuvwxy
cipher text: sghr hr z sdrs
plain text: this is a test
Too easy. Since a simple offset of the standard alphabet is so easy, we need to make it more interesting. We will apply a key to the cipher. The key is any word (I will only be using English). To apply a key, start your cipher by writing out the key, minus any duplicate letters. Say our key is "java". We will begin writing our cipher like this: jav. Notice we dropped the duplicate 'a'. To complete the cipher simply write the rest of the alphabet minus any letters used by your key. This would give us:
<pre>
Cipher: javbcdefghiklmnopqrstuwxyz
Offset +1: zjavbcdefghiklmnopqrstuwxy
cipher text: sghr hr j sdrs
plain text: this is a test
</pre>
Still pretty simple. Here's where we throw in a monkeywrench. We will apply a hat to the cipher in order to rearrange it. A hat, like a key, is a word. Let's use "rancher" as an example. To apply the hat, we first need to write it down, and then under each letter, place a number which equates to it's natural sorted order. Duplicate letters are numbered according to their appearance in the hat, For example:
rancher
6152437
Another one:
freeload
58346712
Get the idea? Next step is to place the cipher row-wise in the columns under the hat.
<pre>
rancher
6152437
-------
javbcde
fghiklm
nopqrst
uwxyz
</pre>
Now we have enough to apply the hat to the cipher. To make your new cipher, pull each column according to it's numbered order. Using the example above, since the 1 is under the second column, we would begin our cipher with: agow. Continuing on to 2, which is the fourth column, we now have: agowbiqy. When we finish, our cipher, with java as the key, and rancher as the hat, is:
agowbiqydlsckrzvhpxjfnuemt
Using a similar example as earlier, using an offset of +1 to encrypt:
<pre>
Cipher: agowbiqydlsckrzvhpxjfnuemt
Offset +1: tagowbiqydlsckrzvhpxjfnuem
cipher text: mvbl bl t mulm
plain text: this is a test
</pre>
Now that you have the basic info, how do you solve these things? I'll pretty much leave that up to you, since that's half the fun. What I will suggest is that you look for common letter combinations (such as 'th'), prefixes (such as 'pre'), and suffixes (such as 'ing', 'es', 'ed', etc...). Short one or two-letter words are good places to make guesses. Another useful tool might be doing a frequency count of the letters. In English the most common letters are A-E-I-N-O-R-S-T, and the least common are J-K-Q-X.
The objective: For each puzzle I will present a few different bits of cipher text, all using different offsets against the same cipher. The primary objective is to recover the plain text. Bonus points if you can figure out the cipher, hat, and key.
Good luck.
[This message has been edited by Jason Menard (edited November 27, 2001).]
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Just as a point of clarification, I don't think it is possible to recover the word used for the hat (outside of a very good guess), but it is possible to recover the sequence the hat generates. That is if the hat is 'rancher', the sequence would be '6152437'.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Just a little something I threw together last night. It might help a little to solve these. The interface could be improved so feel free to do so. Saves on erasers.

Edit: Removed the space from being a valid character for the cryptoLetter filter. Should be able to change to spaces but not actually change the spaces from the original.
[This message has been edited by Paul Stevens (edited November 30, 2001).]
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Paul,
I think I'm a little confused on how to use it. I'm sure it's intuitive, but I'm not. Do you have any instructions?
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
As long as we are sharing code... Here is the code I use to come up with the ciphers and encrypt the text. There are three files... Cipher.java (the bean that does all the work), CipherFrame.java, and CipherText.java. Caveat: I'm a server-side application programmer by trade and don't play around with this Swing stuff too much. The GUI was thrown together with JBuilder and could probably use many fixes/enhancements. Feel free to let me know of anything that needs to be fixed, or of any improvements.
Cipher.java

CipherFrame.java

CipherText.java

[This message has been edited by Jason Menard (edited November 30, 2001).]
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Originally posted by Jason Menard:
Paul,
I think I'm a little confused on how to use it. I'm sure it's intuitive, but I'm not. Do you have any instructions?

Nevermind, I figured it out.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Instructions are for sissies
Copy from your post paste in the text field at the bottom. Click add. Copy as many as there are and click the end button.
The crypts will appear. Put in the letter from the crypt the letter you want to change, which crypt to change and click update. Those components are in the order I just described. I didn't really spend much time creating this so design and instructions where kind of left out.
PS to blank out a letter put the crypt letter and put a space for the replacing letter.
[This message has been edited by Paul Stevens (edited November 30, 2001).]
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
I never saw your post asking for directions. It was sandwhiched between my long code post and yours and I missed it. Sorry.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Bump.


"I'm not back." - Bill Harding, Twister
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
See this page for useful info on solving these problems.
 
jQuery in Action, 2nd edition
 
subject: Crypto Challenge Instructions
 
Similar Threads
Cezar cipher problem
Programming Diversion 2b: Applying a hat
Caesar cipher
Programming Diversion 2a: Applying a Key
crypt algorithm