resourceBook - Eastern Michigan University

advertisement
CRYPTOGRAPHY
Digital Diva
March 2012
Eastern Michigan University
Professor S. Haynes, shaynes@emich.edu
URL for this material: http://people.emich.edu/shaynes/DigitalDiva2012
Shift
Substitution
Permutation
Tap Code
Steganography
Book Cipher
Playfair
No hay tarea
:-(
Definitions
Plaintext:
Ciphertext:
an unencrypted message
an encrypted message
Cipher: encrypt, ciphertext, encryption algorithm
Encryption: transforming plaintext into ciphertext so that the plaintext is kept a secret; this usually
requires use of a key.
Decryption: transforming ciphertext into plaintext; this usually requires use of a key.
Encode: transform something into something else. For example, English  Spanish, letters to
numbers (a, b, c, … z)  (1, 2, 3, … 26).
Decode: undo an encoding (Spanish  English; (1, 2, 3, … 26)  (a, b, c, … z) ).
Algorithm: A sequence of instructions to accomplish something.
Key: Something that is known to the sender and the receiver of a message and is used to encrypt and
decrypt messages.
Secret key (aka private key, symmetric key, shared key): the sender and the receiver have exactly the
same key. The sender encrypts with the secret key, the receiver decrypts with the same secret key.
Public key (aka asymmetric key): a key that comes in two parts: (1) public and (2) private.
Shift cipher: To encrypt plaintext, shift each plaintext letter to the right by key steps. To decrypt
ciphertext, shift each ciphertext letter to the left by key steps.
Substitution cipher: Each plaintext letter is converted to a specific cipher text letter; each cipher text
letter is decrypted to the original plaintext letter.
Steganography: the secret message is hidden in another message.
Alice: the sender of a message
Bob: the receiver of a message
This discussion is important if you program a computer to do cryptography or cryptanalysis.
Modular arithmetic: The rules for addition (subtraction) and multiplication (division) in a list of
consecutive integers like 0, 1, 2, 3. We do modular arithmetic when using a 12 hour clock, a 7 day
week, a 12 month year. Anything that does wrap-around can be described using modular arithmetic.
To do modular arithmetic, you have to start with 0. So for a 12 hour clock: 0, 1, 2, … , 11; for English
letters: (a, b, c, …, z)  (0, 1, 2, … 25).
Modulus: the number of consecutive integers, starting with 0, being used in modular arithmetic. For
letters in English, the modulus is 26 (mod 26), for hours on a 12-hour clock: mod 12, for months in a
year: mod 12, for days in a week: mod 7.
Finding x mod k.
One way to find x mod k, where x >= 0, is to do integer division x/k. The remainder is x mod k.
Examples:
10 mod 3:
10/3 = 3 rem 1 (“10 divided by 3 equals 3 with a remainder of 1”)
10 mod 3 = 1
10 mod 4:
10/4 = 2 rem 2.
So, 10 mod 4 is 2
13 mod 2:
13/2 = 6 rem 1.
So, 13 mod 2 is 1
897 mod 63:
897/63 = 14 rem 15.
So, 897 mod 63 is 15
Another way is to count up (or down).
Examples:
10 mod 3 = 1
regular integers:
modulus 3:
0 1 2 3 4 5 6 7 8 9 10
0 1 2 0 1 2 0 1 2 0 1
10 mod 4 = 2
regular integers: :
modulus 4:
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 0 1 2 3 0 1 2
13 mod 2 = 1
regular integers: :
modulus 4:
0 1 2 3 4 5 6 7 8 9 10 11 12 13
0 1 0 1 0 1 0 1 0 1 0 1 0 1
Shift cipher
1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
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
Caesar cipher uses shared key = 3
Encryption algorithm: Each plaintext letter is encrypted as the letter three spaces to the right with
wrap-around.
Decryption algorithm: Each ciphertext letter is encrypted as the letter three spaces to the left with
wrap-around.
Example Encryption
Plaintext:
lazy one
Ciphertext:
odcb rqh
Example Decryption
Ciphertext:
tzlc
Plaintext:
quiz
To implement this on the computer
Encryption: p  c
- Encode plaintext character p as x, where x is an integer 0 – 25 (see above)
x = encode(p)
- Encrypt x using Caesar cipher algorithm
y = ( x + 3 ) mod 26
- Decode y to ciphertext character
c = decode(y)
Decryption: c  p
- Encode ciphertext character c as y, where y is an integer 0 – 25 (see above)
y = encode(c)
- Decrypt
x = ( y – 3 ) mod 26
- Decode y to ciphertext character
c = decode(y)
plaintext:
Encode:
Encrypt:
Ciphertext:
t
19
24
Y
a
0
3
D
k
10
13
N
e
4
7
H
m
12
15
P
o
14
17
R
r
17
20
U
e
4
7
H
q
16
19
T
u
20
23
X
i
8
11
L
z
25
2
C
z
25
2
C
e
4
7
H
s
18
21
V
Substitution cipher
Each plaintext letter is matched to a unique ciphertext letter.
Example
Plaintext: 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
Ciphertext: Z A B Y C D X E F W G H V I J U K L T M N S O P R Q
The key for a substitution cipher is a permuted alphabet.
Simple ways to form a key:
- a shift cipher is a substitution cipher
- reverse the alphabet
- pick a word or phrase, e.g., “go green beat toledo”. Write down each letter in order from the
phrase under the alphabet, without repetition. Then complete the alphabet by copying the
unused letters in order. You’ll see the same idea in Playfair cipher later.
Example:
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
G O R E N B A T L D C F H I J K M P Q S U V W X Y Z
Permutation
The key is the permutation order.
Break the plain text message into blocks of size k. Number the letters in each block in order 0, 1, 2, …
k-1.
Encrypt each block separately following the permutation order given by the key.
To decrypt, find the permutation that will undo the encryption permutation. Then follow the same
steps as encryption with the new (inverse) permutation.
Example
Block size = 8
Key (permutation order) = 7 6 5 4 3 2 1 0
To undo permutation: 7 6 5 4 3 2 1 0
(the next example will be different)
Encryption:
Plaintext: now is the time for all good men
Labelled blocks:
0 1 2 3 4 5 6 7
n o w i s t h e
0 1 2 3 4 5 6 7
t i m e f o r a
0 1 2 3 4 5 6 7
l l g o o d m e
0 1 2 3…
n x q x…
Write out the blocks where the characters are permuted according to the key:
E H T S I W O N
A R O F E M I T
E M D O O G L L
X Q X…
Example
Block size = 8
key = 0 7 1 2 6 5 3 4
to undo permutation: 0 2 3 6 7 5 4 1
Labelled blocks:
0 1 2 3 4 5 6 7
n o w i s t h e
0 1 2 3 4 5 6 7
t i m e f o r a
0 1 2 3 4 5 6 7
l l g o o d m e
0 1 2 3…
n x q x…
Permute according to the key
N E O W H T I S
T A I M R O E F
L E L G M D O O
N X X…
To decrypt:
0 1 2 3 4 5 6 7
N E O W H T I S
0 1 2 3 4 5 6 7
T A I M R O E F
0 1 2 3 4 5 6 7
L E L G M D O O
0 1 2
N X X…
n o w i s t h e
t i m e f o r a
l l g o o d m e
n x q …
Tap Code
The plain text is given inside the grid, the cipher text is the corresponding row and column numbers.
So for the letter ‘i’, you would tap two times for the row, then four times for the column: ..
1
2
3
4
5
1
A
F
L
Q
V
2
B
G
M
R
W
3
C
H
N
S
X
4
D
I
O
T
Y
....
5
E
J
P
U
Z
The space between letters is a little longer than the space between row and column. End of sentence
is marked with ‘x’ (..... ... )
Use the letter ‘C’ if you need a ‘K’.
Steganography
Hidden writing has many possibilities:
Invisible ink
“Subliminal advertising”
“Meaningful” stitches in quilts (e.g., 3 french knots to indicate a ‘c’, 4 to indicate a ‘d’)
Pin pricks in letters
For our example, we’re using differences in style to mark significant letters or words.
“Book cipher”
To my memory, Sherlock Holmes broke two ciphers. One was a simple substitution cipher. The other
was a book cipher.
To use a book cipher, sender and receiver must agree on exactly the same edition and printing of a
particular book. In the old days, they might use a common version of the Bible (in the case of the
recent Sherlock program, they use a particular travel guide) or a dictionary. Hence the name.
The key is how the address of a word is specified, for example: page#, line#, word#
Each word of the plaintext is encrypted by finding the word in the common text, then producing that
word’s address as the ciphertext.
For example, let us use the song by Alan Sherman as our common text:
Hello Muddah, hello Fadduh,
Here I am at Camp Grenada
Camp is very entertaining
and they say we'll have some fun if it stops raining.
I went hiking with Joe Spivy
He developed poison ivy
You remember Leonard Skinner
He got ptomaine poisoning last night after dinner.
All the counselors hate the waiters
And the lake has alligators
And the head coach wants no sissies
So he reads to us from something called Ulysses.
Now I don't want this should scare ya
But my bunkmate has malaria
You remember Jeffrey Hardy
They're about to organize a searching party.
Take me home, oh muddah fadduh, take me home, I hate Grenada
Don't leave me out in the forest where I might get eaten by a bear.
Take me home, I promise I will not make noise or mess the house with
other boys, oh please don't make me stay, I've been here one whole day.
Dearest fadduh, darling muddah,
How's my precious little bruddah?
Let me come home if ya miss me
I will even let Aunt Bertha hug and kiss me.
Wait a minute, it stopped hailing,
Guys are swimming, guys are sailing,
Playing baseball, gee that's better,
Muddah Fadduh kindly disregard this letter.
Let us specify the key is (paragraph#, line#, word#)
We can encrypt “leave letter at house” as:
5 2 2
7 4 6
1 2 4
5 3 14
Playfair cipher
This cipher uses a 5 X 5 grid, where the letters of the alphabet are laid out (I and J occupy the same
cell). The key is a word or phrase.
To fill in the grid, copy the key, without any duplication of the letters (left to right, top to bottom),
then fill in the rest of the grid with any unused letters in order.
Example grid: key = “crypto rocks”
C
O
D
I/J
U
R
K
E
L
V
Y
S
F
M
W
P
A
G
N
X
T
B
H
Q
Z
To encrypt:
Divide the plain text into two letter blocks with the following “fix”: no block can have two identical
letters. To avoid that, insert an ‘x’ after the first letter.
Example:
calling gramma
ca lx li ng gr am ma
^
Find the two letters of a single block on the grid.
There are three possibilities:
(1) The two letters form two of the four corners of a rectangle (e.g., ‘ca’)
output the other two corners, row first ca  PO
pk  RA
(2) The two letters are on the same row (e.g., ‘ks’)
Output the two letters found by moving one space right of each letter: ks  SA
If you run out of room on the right, then do wrap-around: eh -> FD
(3) The two letters are on the same column (e.g., ‘ag’)
Output the two letters found by moving one space down from each letter:
ag  GN, Rl  KV.
If you run out of room on the bottom, then do wrap-around:
rv  KR, gx  NP
Decryption:
Case (1), same as for encryption.
Case (2), move left
Case (3), move up
Download