Computer Science 101 Cryptography Part I. Notes based on S. Singh, The Code Book: The Evolution of...

Post on 29-Dec-2015

217 views 1 download

Tags:

transcript

Computer Science 101

CryptographyPart I

Notes based on

• S. Singh, The Code Book: The Evolution of Secrecy from Mary, Queen of Scots to Quantum Cryptography. New York: Doubleday (1999)

Terminology

• Steganography – Hiding the message– Under wax of wooden tablets– Shaved heads– Within hardboiled eggs – special ink– Invisible ink– Embedded in pictures or tunes

Crypto: The Problem

ALICE

How do I love thee? Let me count the ways.I love thee to the depth and breadth and heightMy soul can reach, when feeling out of sightFor the ends of Being and ideal Grace.I love thee to the level of every day'sMost quiet need, by sun and candlelight.

abca adf adCIFASFDSFadfafdasf daf pua,kjpui8978*&( aadb adae-898adsf9898b @!!l;kjadsfdsa*()_*()kasjdf*(abac3(*_* ,DAD0-89adfafj&(D()8asdkljfasd;f(_casadfdasfA(()*Aafdafdfas*(ADFSF9-898DFDFSASFDFSDF(*DFSCDFS*(_*(DFS*(adfdsaf(*_)dafdas*ASFD9898-08DFSFDSad*(A(*

BOB

How do I love thee? Let me count the ways.I love thee to the depth and breadth and heightMy soul can reach, when feeling out of sightFor the ends of Being and ideal Grace.I love thee to the level of every day'sMost quiet need, by sun and candlelight.

abca adf adCIFASFDSFadfafdasf daf pua,kjpui8978*&( aadb adae-898adsf9898b @!!l;kjadsfdsa*()_*()kasjdf*(abac3(*_* ,DAD0-89adfafj&(D()8asdkljfasd;f(_casadfdasfA(()*Aafdafdfas*(ADFSF9-898DFDFSASFDFSDF(*DFSCDFS*(_*(DFS*(adfdsaf(*_)dafdas*ASFD9898-08DFSFDSad*(A(*

EVE

Terminology

• Cryptography – Hiding the meaning– Transposition – letters rearranged

• Rail fence

• Wrap around wooden staff

– Substitution – substitute letter for letter, etc.• Caesar cypher – shift

• Key in front (remove repeats – example next)

Example – Key at front

• Suppose we used GEORGE BOOLE as key. Then our encoding would be

ABCDEFGHIJKLMNOPQRSTUVWXYZGEORBLMNPQSTUVWXYZACDFHIJK

• Encoding "TOM WHALEY" would give

CWUHNGTBJ

• This worked for a few centuries (1st millenium AD)

Muslim Scholars

• Mathematics, statistics, linguistics

• Abu Ja' far Muhammad ibn Musa Al-Khowasrizmi (algorithm)

• Algebra

• Cryptanalysis techniques described by al Kindi in 9th century

Frequency Analysis• For a given language (e.g., English), it is

known how often each letter occurs: Letter Percentage

a 8.2

b 1.5

c 2.8

d 4.3

e 12.7

...

z 0.1

Frequency Analysis• So Eve just counts percentages in ciphertext

message, and decrypts it:

Encrypted Percentage Decoded

x 8.2 a

c 1.5 b

p 2.8 c

t 4.3 d

f 12.7 e

...

b 0.1 z

Frequency Analysis

• Only have to encrypt part of the message, and then play “Wheel of Fortune”:

_ o _ d_ I _ _ _e _ _ee _ _et _e _ _ _ _t t_e _ _ _s.

• As length of ciphertext message increases, statistics become more applicable (less so for shorter messages)

Frequency Analysis

• Encrypting pairs helps a lot, but then we just use pairwise frequencies instead:

Pair Percentage

aa 0.0001

ab 0.002

ac 0.003

...

zz 0.0005

Vigenère Ciphers (1586) 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 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 ZB 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 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 BD 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 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 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 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 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 ...

Z 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

– Alice uses a different row to encrypt each letter

– She and Bob use a keyword to switch rows....

Vigenère Ciphers– E.g., keyword FADE:

Keyword F A D E F A D E F A D E F A D

Plaintext h o w d o i l o v e t h e e l

Ciphertext m 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

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

Vigenère Ciphers– E.g., keyword FADE:

Keyword F A D E F A D E F A D E F A D

Plaintext h o w d o i l o v e t h e e l

Ciphertext m o 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

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

Vigenère Ciphers– E.g., keyword FADE:

Keyword F A D E F A D E F A D E F A D

Plaintext h o w d o i l o v e t h e e l

Ciphertext m o 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

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

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

Vigenère Ciphers– E.g., keyword FADE:

Keyword F A D E F A D E F A D E F A D

Plaintext h o w d o i l o v e t h e e l

Ciphertext m o z h 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

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

Vigenère Ciphers– E.g., keyword FADE:

Keyword F A D E F A D E F A D E F A D

Plaintext h o w d o i l o v e t h e e l

Ciphertext m o z h t 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

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

Vigenère Ciphers– Now the code for a word is different each time.

– Alice must send Bob a new key often, or Eve may figure it out – weakness!

– Babbage (1854) : two instances of a common word (the, and, ...) will occasionally look the same:

Keyword K I N G K I N G K I N G K I N G K I N G K I N G

Plaintext t h e s u n a n d t h e m a n i n t h e m o o n

Ciphertext D P R Y E V N T N B U K W I A O X B U K W W B T

– Then use W-o-F techniques to decode.

Vigenère Ciphers– Solution: Use a key the length of the whole message:

Keyword P L M O E Z Q K I J Z L R T E A V C R C B Y N N

Plaintext t h e s u n a n d t h e m a n i n t h e m o o n

Ciphertext I S Q G Y M Q X L C G P D T R I I V Y G N M B A

– Problem: making lots of truly random keys

• People are lazy and will make patterns in keys

• Truly random numbers are difficult to generate automatically (a huge field)

– Bob & Alice share a “one-time-pad” of keys, one for each new message (or new day, week, ...)

Vigenère Ciphers

• Cracked by Charles Babbage in 1854

• Common word will occasionally be encrypted the same way.

The Enigma Machine (1926-1945)

– Alice types on keyboard.

– Scramblers (rotors) randomly wire keyboard to lamps.

– Lamp shows encrypted letter.

– Scrambler rotates as Alice types.

– Scramblers can be removed and swapped with each other.

– Add a plugboard to randomize some of the keyboard/scrambler connections.

The Enigma Machine

– If Eve doesn't have an Enigma machine, she'll never decode a message.

– Assuming she has an exact copy of the machine, there are:

• 26*26*26 = 17,576 possible configurations of three scramblers

• Six possible orders of three scramblers for each such config

• Millions or billions of ways of wiring plugboard

• Therefore over 10,000,000,000,000,000 possible ways of setting up the machine

– So Eve must get an Enigma machine, and intercept the updated Bob/Alice scrambler/plugboard settings.

Cracking the Enigma: Rejewski, Turing

• A combination of espionage, genius, and brute force:– Get hold of an enigma machine or blueprints– Obtain some knowledge about what's being

transmitted to eliminate most possibilities for initial setup:

• Part of initial setup was sometimes specified in message itself

• Early-morning messages had the word weather in specific places (crib: AXQEPAZ = weather)

• Military messages are more rigidly structured (predictable) than everyday language.

Cracking the Enigma: Rejewski, Turing

• A combination of espionage, genius, and brute force:– Build a model of how the machine operates, to

eliminate more possibilities • Isolate components; e.g., ignore the plugboard, and build a

model of the scramblers.

• Check correlations between input and output:– Put in M1, get C1

– Put in M2, get C2

– M1 is to C1 as M2 is to C2

– Check every remaining possibility.