Security in Computing Character Frequencies (English ...

4 downloads 400 Views 3MB Size Report
2. 5 cryptographer's counter-move cryptanalysts use properties of plaintext what can be cryptographers' counter-moves? Pfleeger, Security in Computing, ch. 2.
monoalphabetic cryptanalysis

Common English Digrams and Trigrams Digrams EN RE ER NT TH ON IN TF AN OR



Trigrams ENT ION AND ING IVE TIO FOR OUR THI ONE

3

Pfleeger, Security in Computing, ch. 2

See class example

4

Pfleeger, Security in Computing, ch. 2

Character Frequencies (English) 14 12

Security in Computing

10

percent

8

Chapter 2

6 4

Elementary Cryptography (part 2)

2 0

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

characters Pfleeger, Security in Computing, ch. 2

1

Pfleeger, Security in Computing, ch. 2

2

Vigenere Tableau

Vigenere Cipher 

construct a table (a Vigenere tableau)



each row in table is a different shift (alphabet)



sender and receiver agree on sequence of rows



helps to disguise patterns

Pfleeger, Security in Computing, ch. 2

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

7

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

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 A

cryptanalysts use properties of plaintext



what can be cryptographers' counter-moves?

F G H I J K L M N O P Q R S T U V W X Y Z A B C D E

G H I J K L M N O P Q R S T U V W X Y Z A B C D E F

H I J K L M N O P Q R S T U V W X Y Z A B C D E F G

I J K L M N O P Q R S T U V W X Y Z A B C D E F G H

J K L M N O P Q R S T U V W X Y Z A B C D E F G H I

K L M N O P Q R S T U V W X Y Z A B C D E F G H I J

L M N O P Q R S T U V W X Y Z A B C D E F G H I J K

M N O P Q R S T U V W X Y Z A B C D E F G H I J K L

N O P Q R S T U V W X Y Z A B C D E F G H I J K L M

O P Q R S T U V W X Y Z A B C D E F G H I J K L M N

P Q R S T U V W X Y Z A B C D E F G H I J K L M N O

Q R S T U V W X Y Z A B C D E F G H I J K L M N O P

R S T U V W X Y Z A B C D E F G H I J K L M N O P Q

S T U V W X Y Z A B C D E F G H I J K L M N O P Q R

T U V W X Y Z A B C D E F G H I J K L M N O P Q R S

U V W X Y Z A B C D E F G H I J K L M N O P Q R S T

V W X Y Z A B C D E F G H I J K L M N O P Q R S T U

W X Y Z A B C D E F G H I J K L M N O P Q R S T U V

X Y Z A B C D E F G H I J K L M N O P Q R S T U V W

Y Z A B C D E F G H I J K L M N O P Q R S T U V W X

Z 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

8

polyalphabetic ciphers





multiple possible output characters for an input character

polygram ciphers ––

5

use multiple alphabets

homophonic ciphers ––

Pfleeger, Security in Computing, ch. 2

E F G H I J K L M N O P Q R S T U V W X Y Z A B C D

Hiding Patterns ––



D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

Pfleeger, Security in Computing, ch. 2

cryptographer's counter-move 

C D E F G H I J K L M N O P Q R S T U V W X Y Z A B

encipher groups of letters at once

Pfleeger, Security in Computing, ch. 2

6

Don't Need to Construct the Table

More on Vigenere Keys 





usually think of choice of rows as a keyword example: keyword ““BASE”” row order is b,a,s,e,b,a,s,e, ...

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

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

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 A

C D E F G H I J K L M N O P Q R S T U V W X Y Z A B

D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

E F G H I J K L M N O P Q R S T U V W X Y Z A B C D

F G H I J K L M N O P Q R S T U V W X Y Z A B C D E

G H I J K L M N O P Q R S T U V W X Y Z A B C D E F

H I J K L M N O P Q R S T U V W X Y Z A B C D E F G

I J K L M N O P Q R S T U V W X Y Z A B C D E F G H

J K L M N O P Q R S T U V W X Y Z A B C D E F G H I

K L M N O P Q R S T U V W X Y Z A B C D E F G H I J

L M N O P Q R S T U V W X Y Z A B C D E F G H I J K

M N O P Q R S T U V W X Y Z A B C D E F G H I J K L

N O P Q R S T U V W X Y Z A B C D E F G H I J K L M

O P Q R S T U V W X Y Z A B C D E F G H I J K L M N

P Q R S T U V W X Y Z A B C D E F G H I J K L M N O

Q R S T U V W X Y Z A B C D E F G H I J K L M N O P

R S T U V W X Y Z A B C D E F G H I J K L M N O P Q

S T U V W X Y Z A B C D E F G H I J K L M N O P Q R

T U V W X Y Z A B C D E F G H I J K L M N O P Q R S

U V W X Y Z A B C D E F G H I J K L M N O P Q R S T

V W X Y Z A B C D E F G H I J K L M N O P Q R S T U

W X Y Z A B C D E F G H I J K L M N O P Q R S T U V

X Y Z A B C D E F G H I J K L M N O P Q R S T U V W

Y Z A B C D E F G H I J K L M N O P Q R S T U V W X

11

Pfleeger, Security in Computing, ch. 2

Z 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



––



suppose we agree on the key{1,5,9,16,21,22} encrypt: ––

char 1 with row 1

––

'

2 '

' 5

––

'

3 '

' 9

...

–– ––

char 6 with row 22

––

char 7 with row 1

––

char 8 with row 5

––

etc.

Pfleeger, Security in Computing, ch. 2

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

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

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 A

C D E F G H I J K L M N O P Q R S T U V W X Y Z A B

D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

E F G H I J K L M N O P Q R S T U V W X Y Z A B C D

F G H I J K L M N O P Q R S T U V W X Y Z A B C D E

G H I J K L M N O P Q R S T U V W X Y Z A B C D E F

H I J K L M N O P Q R S T U V W X Y Z A B C D E F G

I J K L M N O P Q R S T U V W X Y Z A B C D E F G H

J K L M N O P Q R S T U V W X Y Z A B C D E F G H I

K L M N O P Q R S T U V W X Y Z A B C D E F G H I J

L M N O P Q R S T U V W X Y Z A B C D E F G H I J K

M N O P Q R S T U V W X Y Z A B C D E F G H I J K L

N O P Q R S T U V W X Y Z A B C D E F G H I J K L M

equivalent K={1, 17, 0, 10, 4}



plaintext ““I am sick of school””



convert to numeric vals



add to K mod 26

+

I 8

A M 0 12

S I C K 18 8 2 10

O F 14 5

S C H O O L 18 2 7 14 14 11

B 1

R A 17 0

K E B R 10 4 1 17

A K 0 10

E B R A K E 4 1 17 0 10 4

9

17 12

2 12 3 1

14 15

22 3 24 14 24 15

12

Pfleeger, Security in Computing, ch. 2

Vigenere Example

Vigenere Example 

keyword = BRAKE

O P Q R S T U V W X Y Z A B C D E F G H I J K L M N

P Q R S T U V W X Y Z A B C D E F G H I J K L M N O

Q R S T U V W X Y Z A B C D E F G H I J K L M N O P

R S T U V W X Y Z A B C D E F G H I J K L M N O P Q

S T U V W X Y Z A B C D E F G H I J K L M N O P Q R

T U V W X Y Z A B C D E F G H I J K L M N O P Q R S

U V W X Y Z A B C D E F G H I J K L M N O P Q R S T

V W X Y Z A B C D E F G H I J K L M N O P Q R S T U

W X Y Z A B C D E F G H I J K L M N O P Q R S T U V

X Y Z A B C D E F G H I J K L M N O P Q R S T U V W

9

Y Z A B C D E F G H I J K L M N O P Q R S T U V W X

Z 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

M = ““Chappelle”” K = 1,5,9,16,21,22 EK(M) = DMJFKAMQN 

note: our key is in ascending order. this isn't required

Pfleeger, Security in Computing, ch. 2

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

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

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 A

C D E F G H I J K L M N O P Q R S T U V W X Y Z A B

D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

E F G H I J K L M N O P Q R S T U V W X Y Z A B C D

F G H I J K L M N O P Q R S T U V W X Y Z A B C D E

G H I J K L M N O P Q R S T U V W X Y Z A B C D E F

H I J K L M N O P Q R S T U V W X Y Z A B C D E F G

I J K L M N O P Q R S T U V W X Y Z A B C D E F G H

J K L M N O P Q R S T U V W X Y Z A B C D E F G H I

K L M N O P Q R S T U V W X Y Z A B C D E F G H I J

L M N O P Q R S T U V W X Y Z A B C D E F G H I J K

M N O P Q R S T U V W X Y Z A B C D E F G H I J K L

N O P Q R S T U V W X Y Z A B C D E F G H I J K L M

O P Q R S T U V W X Y Z A B C D E F G H I J K L M N

P Q R S T U V W X Y Z A B C D E F G H I J K L M N O

Q R S T U V W X Y Z A B C D E F G H I J K L M N O P

R S T U V W X Y Z A B C D E F G H I J K L M N O P Q

S T U V W X Y Z A B C D E F G H I J K L M N O P Q R

T U V W X Y Z A B C D E F G H I J K L M N O P Q R S

U V W X Y Z A B C D E F G H I J K L M N O P Q R S T

V W X Y Z A B C D E F G H I J K L M N O P Q R S T U

W X Y Z A B C D E F G H I J K L M N O P Q R S T U V

X Y Z A B C D E F G H I J K L M N O P Q R S T U V W

10

Y Z A B C D E F G H I J K L M N O P Q R S T U V W X

Z 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

Homophonic Example Plaintext



Homophonic Ciphers (cont'd)

Homophones

A B C D E F G

624 5 919 414 8 61 413

18 333 14 309 13 422 2

329 511 67 238 12

...

...

...

...

19

4

83 71

15



6

16

...

... ...

So ““cabbage”” could be encrypted as: ––

14 329 511 5 624 2 8 15

Pfleeger, Security in Computing, ch. 2

Pfleeger, Security in Computing, ch. 2

Don't Need to Construct the Table 

Are there disadvantages to this?

Homophonic Ciphers

keyword = BRAKE ––

equivalent K={1, 17, 0, 10, 4}



plaintext ““I am sick of school””



convert to numeric vals



add to K mod 26

+



Encrypts to: J RM CMDB OP WDYOYP

A M 0 12

S I C K 18 8 2 10

O F 14 5

S C H O O L 18 2 7 14 14 11

B 1

R A 17 0

K E B R 10 4 1 17

A K 0 10

E B R A K E 4 1 17 0 10 4

9

17 12

2 12 3 1

14 15

22 3 24 14 24 15

Pfleeger, Security in Computing, ch. 2





I 8

16

13

Try to hide plaintext patterns Map each plaintext character m to any of a set of ciphertext characters set of possible ciphertext characters that map to a single plaintext character m called homophones

Pfleeger, Security in Computing, ch. 2

14

Playfair Cipher

Playfair Encryption



1850s. named after Playfair



actually invented by his friend Wheatstone



write keyword without dups. into 5x5 matrix

 

treat I and J as the same character example: ––

keyword ““MACARONI””

M N F P V

A I/J G Q W

C B H S X

R D K T Y

divide plaintext into pairs



O E L U Z

Pfleeger, Security in Computing, ch. 2

double characters separated by dummy character (e.g. x)



mi ss is si pp i becomes

––

mi sx si sx si px pi



ciphertext longer than the plaintext 



How many homophones per plaintext char? –– ––

fixed number variable: more for frequent plaintext characters

Pfleeger, Security in Computing, ch. 2

only 3 possibilities ––

same row

––

same column

––

different row and col.

20

Polygram Ciphers

Are there disadvantages to this? ––



Pfleeger, Security in Computing, ch. 2

Homophonic Ciphers (cont'd) 

encrypt plaintext pairs

if plaintext has odd number of chars, append dummy char.



19

––







17

simple substitution ciphers, e.g. shift ciphers, keyword mixed alphabet, (even Vigenere tableau) ... substitute one character for another character polygram ciphers substitute a group of characters for another group of characters goal: make frequency analysis more difficult examples: ––

playfair cipher

––

hill cipher

Pfleeger, Security in Computing, ch. 2

18

One time pad

One time pad 



Idea: ––

Take a stream of random data (keystream)  

–– 

used to be physically on a pad. rip out as many random pages as you need.



Combine it with plaintext to form ciphertext

Message receiver uses same keystream to recover plaintext



Take a stream of random data (keystream)

––

Combine it with plaintext to form ciphertext

Message receiver uses same keystream to recover plaintext



If the stream is truly random  perfect security



Why don't we use this all the time?

If the stream is truly random  perfect security

––

How do we get unlimited truly random stream?



Why don't we use this all the time?

––

If we could get it, how do we distribute it?

––

What if sender and receiver aren't synchronized?

23

same row ––

substitute with chars to right

––

examples: MCAR, RMOA,SUTP

same col ––

substitute with chars below

––

examples: EULZ, GWQA

M N F P V

A I/J G Q W

C B H S X

Playfair –– different row and col R D K T Y



O E L U Z



M N F P V

different row and col  tricky

Pfleeger, Security in Computing, ch. 2

24

Pfleeger, Security in Computing, ch. 2

Playfair encryption (cont'd)



––



Pfleeger, Security in Computing, ch. 2



Idea:

21

substitute plaintext letter with letter that ––

is in its own row

––

and is in the column of the other plaintext letter

example, AT becomes RQ

A C R O I/J B D E G H K L Q S T U W X Y Z

Pfleeger, Security in Computing, ch. 2

M

A

C R O D K T Y

P

A I/J G Q W

S

T U

22

Reusing the stream 

Combining Plaintext with Keystream

So why can't we just reuse the DVD? ––



It's very insecure: more on this later

27

Pfleeger, Security in Computing, ch. 2

Can do it a different ways: ––

XOR

––

If text, can add to key (mod 26)

Quick Quiz 



28

Pfleeger, Security in Computing, ch. 2

Quick Quiz

I have:



I have:

––

DVD ( 5 GBytes) of random data

––

DVD ( 5 GBytes) of random data

––

a 1.5 Mbps DSL

––

a 1.5 Mbps DSL

If I copy the DVD and give it to a friend, how long can we use it as a one-time pad?



If I copy the DVD and give it to a friend, how long can we use it as a one-time pad?

5GBytes1024MBytes/GByte8bits/byte =27,306secs.=about 7.5hours 1.5Mbps Pfleeger, Security in Computing, ch. 2

25

Pfleeger, Security in Computing, ch. 2

26

XOR (cont'd)

XOR (cont'd)

a  a=?

a  a=0

a  b  b=?

a  b  b=a XOR is an involution 31

Pfleeger, Security in Computing, ch. 2

XOR 

XOR

Review: XOR logic operator

A

B

A XOR B

FALSE FALSE TRUE TRUE

FALSE TRUE FALSE TRUE

FALSE TRUE TRUE FALSE

Pfleeger, Security in Computing, ch. 2

32

Pfleeger, Security in Computing, ch. 2

29



XOR often denoted 



Don't have to write the words TRUE, FALSE



The following are equivalent:

A

B

FALSE FALSE TRUE TRUE

FALSE TRUE FALSE TRUE

A B FALSE TRUE TRUE FALSE

Pfleeger, Security in Computing, ch. 2

A

B

0 0 1 1

0 1 0 1

A B 0 1 1 0 30

XOR Example  

XOR in Java

can encrypt by XORing plaintext with keystream Example: plaintext = ““Chappelle””



XOR it the keystream with the ciphertext.

Pfleeger, Security in Computing, ch. 2

35

System.out.println(plaintext.charAt(i) + "\t" + Integer.toBinaryString((int)plaintext.charAt(i)) + "\t" + key[i] + "\t" + Integer.toBinaryString(key[i])+ "\t" + Integer.toBinaryString((int)plaintext.charAt(i) ^ key[i]));

Pfleeger, Security in Computing, ch. 2



––

f a bijection (11, onto) from S to S (i.e. f: S  S)





can encrypt by XORing plaintext with keystream



Example: plaintext = ““Chappelle””

c C h a p p e l l e c(bin) 01000011 01101000 01100001 01110000 01110000 01100101 01101100 01101100 01100101 key 33 72 31 79 82 74 126 89 2 key(bin) 00100001 01001000 00011111 01001111 01010010 01001010 01111110 01011001 00000010 c XOR k 01100010 00100000 01111110 00111111 00100010 00101111 00010010 00110101 01100111

f is an involution if f = f -1 ––

i.e. f(f(x)) = x

So XOR is an involution



Pfleeger, Security in Computing, ch. 2

36

XOR Example

Let: S be a finite set

Code that produced the example: for (int i=0; i