Sunday, August 10, 2014

Blood, sweat, tears, and cryptography

AES (Advanced Encryption Standard) is quite a bit more powerful than the methods described in my previous blog post. It is widely used among private companies and governments to encrypt text, passwords, and file contents. There are several other encryption standards, which I won't delve into. This website provides a free tool to code and decode messages using AES, and so do many others.

On a personal note, those close to me will know that the past two years have brought some of the biggest challenges in my life (don't mean to be dramatic, I swear!), and also some fun memorable moments To all who have been there in some way or another - I would like to thank you in the form of an encrypted message. All you have to do is use the links with your initials to find my individualized salute to you. Oh, and you all have to ask for your individualized link & passwords

JH
FP
PN
TS
JV
LH
NT
JG
ISO
VT



Cryptography, part one

In an alternate universe, after the British used careful analysis of social networks (great short article, do read) to narrow in on Paul Revere, the colonial hero did not have much time to deliver his famous message. Knowing he may be caught at any moment, he decided to encrypt his message. That is, to turn words into code

Paul Revere - silversmith, patriot, and amateur code boy


 His first attempt was rather weak - turning all letters to corresponding numbers.

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z *
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Figure 1
His message now looked like this

T H E * B R I T I S H * A R E * C O M I N G
20 8 5 27 2 18 9 20 9 19 8 27 1 18 5 27 3 15 13 9 14 7
Figure 2

This "code" could easily be intercepted by anyone who read the numbers.  So he tried again, with a slightly more complex replacement - he split the alphabet into 3, and gave each letter a number and a symbol, going backwards:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z *
9* 8* 7* 6* 5* 4* 3* 2* 1* 9^ 8^ 7^ 6^ 5^ 4^ 3^ 2^ 1^ 9$ 8$ 7$ 6$ 5$ 4$ 3$ 2$ 1$
Figure 3

The message could now be written and passed on more discreetly, but it was still not secure. If the police caught Revere and intercepted his letter, it would be only a short matter of time until they figure out the one-to-one correspondence between letter and code. How could Revere ensure a more random coding and translation? Since he did not have access to modern computing, the answer was matrices.

Matrices can be used as a mathematical basis for cryptology. Using a numerical message, such as in Figure 2, we can use matrix multiplication to "jumble up" numbers to a substantial degree of randomness, making coded messages more difficult to decipher. Besides the message itself, the process requires an encoding matrix, which must be square in shape and invertible (if you are rusty on matrix algebra, don't worry about this part). The larger the square encoding matrix, the more secure the encryption. We will use the following 3x3 matrix below, with message matrix split into columns of 3 for multiplication purposes.

7 2 1
0 3 -1
-3 4 -2
With encoding matrix above, multiply by message matrix below. The message matrix is the original numerical message, [20,8,5,27,2,18...] transposed into columns of 3
20 27  9  19  1  27  13  7
8  2  20  8  18  3  19  27
5 18 9  27  5  15  14  27

The following matrix results: 
161 211 112 176 48 210 143 130
19 -12   51   -3   49   -6   43  54
-38 -109 35 -79  59  -99   9 33

Paul Revere can now write these numbers down on paper, and the code won't be as obvious. For one thing, we are not using 1-27 anymore, and there is no one-to-one correspondence for letters. However, to solve the code, Revere's compatriots will have the key, or the original 3x3 encoding matrix, and multiply its inverse by Revere's transformed new matrix. I won't bother showing these steps - the result, as we've said before, will alert them just in time:

T H E * B R I T I S H * A R E * C O M I N G
20 8 5 27 2 18 9 20 9 19 8 27 1 18 5 27 3 15 13 9 14 7

Happy New Year and Don't Blow Yourself Up: Exploring National Injury Data with Python

Every year, hundreds of thousands of Americans go to the Emergency Room for various injuries resulting from common consumer products. Do you...