Wednesday, 23 March 2011

Cryptography and Cryptanalysis: Affine Cipher Decoding

Last week's answer:  Taz fp D ovdsx kadh?

Last week we learned how to encode affine ciphers. This week we learn to decode.

In affine ciphers the decryption function for a letter denoted by x is
d(x) = a-1(x - b) mod m

First of all, we need to understand a few rules:
  • m is the size of the alphabet - in English it's 26
  • b is in the range (0,m-1)

So, we know that in the equation:
d(which, in this case, stands for decrypt)
(x) = a-1(x - b)(mod 26)

Next, let's find '
a-1'.
I'm not going to explain how to find the inverse to a number (it's a long complicated process - however, if anyone does have a question about this, I will be happy to send you the answer in an email) but for 'a' with {1,3,5,7,9,11,15,17,19,21,23,25} the inverse 'a-1 is {1,9,21,15,3,19,7,23,11,5,17,25}. 




Here's an example:

Lets use (5,8) that means a=5 and b=8. However, the inverse of 5 is 21.
ciphertext: I H H  W V V C S W F R C P
y: 8 7 7 22 21 21 2 18 22 5 17 215
Now, the next step is to compute 21(y − 8), and then take the remainder when that result is divided by 26. The following table shows the results of both computations.
ciphertext: I H H W V C S W F R C P
y: 8 7 7 22 21 2 18 22 5 17 2 15
21(y-8): 0 -21 -21 294 273 -126 210 294 -63 189 -126 147
(21(y-8)) mod 26: 0 5 5 8 13 4 2 8 15 7 4 17
The final step in decrypting the ciphertext is to use the table to convert numeric values back into letters. The plaintext in this decryption is AFFINECIPHER. Below is the table with the final step completed.
ciphertext: I H H W V C S W F R C P
y: 8 7 7 22 21 2 18 22 5 17 2 15
21(y-8): 0 -21 -21 294 273 -126 210 294 -63
-126 147
(21(y-8)) mod 26: 0 5 5 8 13 4 2 8 15 7 4 17
plaintext: A F F I N E C I P H E R

Now your turn:

Decode this with the decryption key (a,b) = (7,5) with the inverse of a being (15,5) and ignore the capitals, spaces and question mark:

Gfi rzpubheo zs ich mftx!


(I will post the answer next week!)
 

Example source: Wikipedia
Picture source: Woot.com

15 comments:

  1. Now I know it's time for me to go to bed...

    ReplyDelete
  2. Hi Clarissa .. this is really testing .. and even though I have coffee - I'm not up to it!

    Very interesting to read about though .. thanks for giving us an insight ..

    PS decoding the A - Z Challenge is more up my street at the moment?! .. cheers Hilary

    ReplyDelete
  3. huh now? Unfortunately there are only pirates swashbuckling and dragons flying in my head - I would suck at playing Nancy Drew :-)

    ReplyDelete
  4. Wow my eyes are buggin'. lol... but I love this kind of stuff. Hmm.. I'll have to get back to you on this...

    ReplyDelete
  5. Clarissa - I find this utterly fascinating and I have so much admiration for people who can create and break codes. I wish I could but my brain just doesn't think that way. I'm going to have to really "chew" on this one...

    ReplyDelete
  6. My head, my beautiful head (with its one brain cell...!).

    Take care
    x

    ReplyDelete
  7. This is one that will take some time (and several more cups of coffee) to understand. You amaze me with your many talents. Interesting post.

    Mason
    Thoughts in Progress

    ReplyDelete
  8. OK...I still understand absolutely nothing about this code. Zero. But I love it. And I like the pi|pie graphic :)

    ReplyDelete
  9. I think I'm failing this math exam ....

    ReplyDelete
  10. Wow, there's like way too many numbers here, LOL! ;)-

    ReplyDelete
  11. Taz fp D ovdsx kadh? I don't understand....and I thought I was doing it so well! ;)

    ReplyDelete
  12. Wow, this is interesting! I need to return when I've got a bit more time to figure this out. And who said math wouldn't come in handy? :)

    ReplyDelete
  13. Intriguing, but wow ...

    I enjoyed reading about this.

    ReplyDelete
  14. That's complicated but fascinating code!

    ReplyDelete
  15. Whew...you were blessed with this ability, but I fear I wasn't! Simple code, yes. Complex code, I want my mommy!

    ReplyDelete

If you don't have anything nice to say, say it anyway.

Popular Posts

Blog Archive