Lecture
28
Today's Agenda
Cryptology
and Computer Security II
CIPHERS
MONALPHABETIC SUBSTITUTION
POLYALPHABETIC SUBSTITUTION
POLYGRAPHIC
SYSTEMS
MONALPHABETIC SUBSTITUTION
Caesar Cipher: Replace each letter of the message by the letter x places beyond it in the normal alphabet.
Numerical Implementation
of Caesar Cipher
1) Replace each letter by its position in the alphabet
2) Add 3 % 26 to the position (treat 0 as 26)
3) Replace resulting number
by its letter equivalent
M
--> 13 --> 16 --> P
In JavaScript
Phrase is variable name; it contains a character string.
The first character in Phrase is Phrase.charAt(0);
Its ASCII value is ascii = Phrase.charCodeAt(0);
Its position in the alphabet is position = ascii - 64
To add 3 mod 26: cipherPosition =(position + 3) % 26
Now cipherPosition is the position of new letter in the alphabet.
Its ASCII value is x = cipherPosition + 64.
The corresponding letter
is String.fromCharCode(x)
Summarizing:
ascii = Phrase.CharCodeAt(0);
position = ascii - 64;
cipherPosition =(position + 3) % 26
NewAscii = cipherPosition + 64
CipherCharacter = String.fromCharCode(NewAscii)
Any rearrangement of the alphabet produces another substitution scheme.
Here is another way to get a rearrangement;
Pick a key word: VERMONT
Make the letters the heads of columns in a table.
Fill in the rest of the alphabet into the table from left to right.
V | E | R | M | O | N | T |
A | B | C | D | F | G | H |
I | J | K | L | P | Q | S |
U | W | X | Y | Z |
Then read the letters out of the table, column by column
going from left to right, reading each column from top to bottom:
VAIU EBJW RCKX MDLY OFPZ
NGQ THS
Encrypt:
(1) Find position of plaintext letter in straight
(2) Replace it with ciphertext in same position in mixed
Example: plaintext character is stored in PlainChar
position = straight.IndexOf(PlainChar)
CipherChar = mixed.charAt( position );
straight = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
mixed
= "VAIUEBJWRCKXMDLYOFPZNGQTHS";
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 |
0 | 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 |
V | A | I | U | E | B | J | W | R | C | K | X | M | D | L | Y | O | F | P | Z | N | G | Q | T | H | S |
Decrypt: Reverse the roles of straight and mixed.
How would you Break a Ciphered Message?
Use the Cryptoanalyst's most powerful tool!
Frequency Analysis:
Standard Written English
E | the highest frequency |
T A O I N S H R | high frequency group |
D L | medium frequency |
C U M W F G Y P B | low frequency |
V K J X Q Z | rare |
With a Caesar Cipher, we only need to know where one letter goes to find the key (since all other letters are shifted the same amount)
How to Use Frequency Analysis
For Caesar Cipher: Do a frequency analysis of the ciphertext. Guess that E was shifted to the most frequent letter and try this shift as the key. Your guess should also be consistent with the following observations about standard written English:
Among High Frequency Letters:
A, E, I are 4 apart (equally spaced)
R, S, T from a consecutive triple
Among Low Frequency Letters;
V, W, X, Y, Z are 5 consecutive lows.
What happens to these
patterns under a shift?
The Federalist Papers
Shakespeare
Hemingway
Deep Throat
Primary Colors