Tuesday, June 06, 2006

Answers to Wei-Hwa's Puzzle Challenge 2 using PERL Code

Leave comments here: 2 comment(s)
There was a cryptography documentary on breaking the WW2 Enigma Code and I joked about solving puzzle 2 with code. I went snooping into the puzzle code only to find out that the answers were embedded into the code (I did some AJAX projects mid last year and realized that the answers were not pulled from a remote server). AHA! I turned puzzle 2 into a puzzle and set out solving this simple encryption using PERL. In about 2 minutes, I figured out how to answer puzzle 2 using PERL code (Using my knowledge of T9 text prediction). :)

Decryption How-To:
After looking at the code, here is the ALL IMPORTANT! Decryption key map (Sorry, do not know the correct definition - pair wise?):

Decryption Key Map (DKM):
Decrypted: abcdefghijklmnopqrstuvwxyz
Encrypted: nopqrstuvwxyzabcdefghijklm
Note: a is n - n is a, b is o - o is b, c is p - p is c, etc.

Wei-Hwa's Code (Find under following comments in his code:
Clean other symbols: // We filter out any input that isn't a letter.
Decryption map: // build a map. (Not very efficient to do this every time, but what the heck.)
Answers: // should probably be a map, but I'm lazy.
Answer List:
  • qnhtugreynhtugre
  • srpnyqrpny
  • sernxoernx
  • travnyqravny
  • trahfzrahf
  • tebffpebff
  • yntrejntre
  • arhgreferhgref
  • cbfgntrubfgntr
  • ubfgntrcbfgntr
  • gbhpurfqbhpurf
  • ivfpbhagqvfpbhag
  • lbhatreybhatre

PERL CODE (Only 3 lines! Actually 2 lines if I did not care about lower case.): (Download code: puzzle2decrypt.pl)

my ( $encryptedWord ) = lc( $decryptedAnswer );
$encryptedWord =~ tr/a-z/nopqrstuvwxyzabcdefghijklm/;
print "Decrypted Answer: $encryptedWord\n\n";
#Anyone want to fix this regex for me? How do you represent n-z and a-m in one line?


Execute Code: (Separate encrypted answers with space)
$ perl puzzle2decrypt.pl qnhtugreynhtugre srpnyqrpny sernxoernx travnyqravny trahfzrahf tebffpebff yntrejntre arhgreferhgref cbfgntrubfgntr ubfgntrcbfgntr gbhpurfqbhpurf ivfpbhagqvfpbhag lbhatreybhatre

Output:
You entered 13 encrypted answer(s) to decrypt.

Encrypted Answer: qnhtugreynhtugre
Decrypted Answer: daughterlaughter

Encrypted Answer: srpnyqrpny
Decrypted Answer: fecaldecal

Encrypted Answer: sernxoernx
Decrypted Answer: freakbreak

Encrypted Answer: travnyqravny
Decrypted Answer: genialdenial

Encrypted Answer: trahfzrahf
Decrypted Answer: genusmenus

Encrypted Answer: tebffpebff
Decrypted Answer: grosscross

Encrypted Answer: yntrejntre
Decrypted Answer: lagerwager

Encrypted Answer: arhgreferhgref
Decrypted Answer: neutersreuters

Encrypted Answer: cbfgntrubfgntr
Decrypted Answer: postagehostage

Encrypted Answer: ubfgntrcbfgntr
Decrypted Answer: hostagepostage

Encrypted Answer: gbhpurfqbhpurf
Decrypted Answer: touchesdouches

Encrypted Answer: ivfpbhagqvfpbhag
Decrypted Answer: viscountdiscount

Encrypted Answer: lbhatreybhatre
Decrypted Answer: youngerlounger

Cool! Must be the Mountain View air. Contact me if you have any questions.

vjbaqrevsjrvujnernqfguvfoybt. qbrfnalbarjnaggbuverncebqhpgznantre

Come back for my puzzles 101 series tomorrow. :)
Digg this blog

Links to this post:

Create a Link

<< Home