spring 2014 codes lecture 2: the caesar & shift · pdf filecryptography codes lecture 2:...

29
Cryptography Codes Lecture 2: The Caesar & Shift Ciphers Spring 2014 Morgan Schreffler Office: POT 902 http://www.ms.uky.edu/ ~ mschreffler

Upload: vanquynh

Post on 22-Mar-2018

220 views

Category:

Documents


3 download

TRANSCRIPT

Cryptography

Codes Lecture 2: The Caesar & Shift CiphersSpring 2014

Morgan SchrefflerOffice: POT 902

http://www.ms.uky.edu/~mschreffler

Cryptography Notation

Definition (Plaintext � and Ciphertext �)

We use the word Plaintext to describe unencrypted/decrypted,readable English. To describe numbers associated to plaintext, weuse the following symbol: �

We use the word Ciphertext to describe encrypted, unreadablelanguage. To describe numbers associated to ciphertext, we usethe following symbol: �

Example

For example, the plaintext message “I” would have � = 9.

If we encrypt this as the ciphertext “T”, we write � = 20.

Congratulations, You Are Now A Spy 1

Example

Your first mission is to intercept and decipher enemycommunications. The enemy is known to use a relatively simpleencryption method.

Enemy agents are after one of several (code named) targets:

DOG, MAN, BOY, DAD, MOM, BIT, BOT

If you intercept the ciphertext message “PRP”, what is thetarget?

Using the enemy agent’s method above, how would theplaintext “HAT” be sent?

Encryption Method: Caesar Cipher

Definition (Encryption: Caesar Cipher)

The Caesar Cipher is a code that encrypts a letter by moving 3units to the right (with alphabetic order). For the letters A–W thiscode can be described using the rule

� + 3 = �.

The letters X, Y, and Z are encrypted as A, B, and C(respectively).Encryption for the Caesar Cipher can be described completelyusing modular arithmetic as

� + 3 (mod 26) = �.

Hail Caesar 1

Example (Hail Caesar 1)

Gaius Julius Caesar has been surrounded during the battle ofAlesia! He needs you to respond to two questions posed by one ofhis Lieutenants. Unfortunately, those filthy Gauls are everywhere!

You will need to encrypt Caesar’s answers:

Question: What do you need?

Caesar’s Answer: WATER

Question: Do we attack tomorrow?

Caesar’s Answer: YES

Hail Caesar 2

Example (Hail Caesar 2)

You return to Caesar with a message from a Lieutenant.

The message gives the time of the next attack. It is encryptedas the following:

GDZQ

Like all Romans, Caesar is extremely superstitious and avoidsmaking actions on the left. If you were to decrypt themessage above by only moving to the right, how much wouldyou have to move by?

Decryption Method: Caesar Cipher

Definition (Decryption: Caesar Cipher)

A Caesar Cipher can be decrypted by moving 3 units to the left(against alphabetic order). For the letters A, B, C this decryptioncan be described using the rule

� + 23 = �.

Technically, the letters D–Z are decrypted by wrapping backaround the alphabet.Decryption for the Caesar Cipher can be described completelyusing modular arithmetic as

� + 23 (mod 26) = �.

Hail Caesar 3

Example (Hail Caesar 3)

One last exchange message before the attack:

Caesar asks you to encrypt and deliver the following message:

FORTUNA

You return with the following encrypted message. Decrypt itfor Caesar:

YLFWRULD

Related Idea: Frequency Analysis

Anyone who has watched Wheel of Fortune or played Scrabbleknows that the English language uses some letters more frequentlythan others.The graph below indicates the relative frequency of letters in theEnglish language.

A

BC D

E

F G

H

I

J K

LM

N O

PQ

R S

T

U

VW

XY

Z

Some codes do not hide the natural frequency of letters.

Related Idea: Frequency Analysis

The Caesar Cipher disguises letters, but does not disguise thenatural frequency of letters!

AB

C

D

EF G

H

I J

K

L

M N

OP

Q R

S

T

U V

W

X

YZ

The most frequent symbol used in the ciphertext will correspond tothe letter “E” in the plaintext. For the Caesar Cipher, thiscorresponds to the numeric 5 + 3 and is the ciphertext letter “H”.

Code Summary: Caesar Cipher

We will talk about several different types of codes during the nextfew weeks and it will be good to keep a summary for each. Theideas behind Encryption Key and Decryption Key for the CaesarCipher will be applicable to all codes. Additionally Key Secrecy,the idea for how secret the decryption key must be, and LetterFrequency, or how much a cipher changes the nature of how oftenletters appear, will become increasingly important. The summarybelow represents information about codes when encrypting anddecrypting English language plaintext.

Encryption Decryption Key LetterCipher Key(s) Key(s) Secrecy FrequencyCaesar 3 23 Private Normal

Hail Caesar 4

Example (Hail Caesar 4)

The attack was a success and the Gauls are now on the run!Unfortunately, they managed to capture a messenger who knowsCaesar’s secrets for encryption and decryption. Caesar decides totry something new. Help him figure it out!

What letter will correspond to 37 (mod 26)?

What letter will correspond to 45 (mod 26)?

What letter will correspond to 57 (mod 26)?

What letter will correspond to 80 (mod 26)?

Encryption Method: Shift Cipher

Definition (Encryption: Shift Cipher)

An English Language Shift Cipher using the shift ∆ moves everyletter of the alphabet ∆ places to the right. The conversion fromEnglish plaintext � to ciphertext � is represented by the formula

� + ∆ (mod 26) = �.

So the Caesar Cipher is just a type of Shift Cipher, but with thespecific value of ∆ = 3.

Allowing for more values for the shift ∆ means more options andmakes for a code that is more challenging to break!

Hail Caesar 5

Example (Hail Caesar 5)

The attack was a success and the Gauls are now on the run!Unfortunately, they managed to capture a messenger who knowsCaesar’s secrets for encryption and decryption. Caesar decides totry something new. Help him figure it out!

Caesar decides to use a shift cipher with ∆ = 5. Encrypt themessage “ATTACK” using this cipher.

The message “KQJJ” was encrypted using the shift cipherwith ∆ = 5. Decrypt the message!

Hail Caesar 6

Example (Hail Caesar 6)

Caesar has used so many different values of ∆ to make shiftciphers that he can’t remember how to decrypt!

Caesar decides to use a shift cipher with ∆ = 11. Tell Caesarhow much he will have to shift to the right in order to decryptmessages encoded with this cipher.

Write a modular equation to represent decryption for this shiftcipher. What does this decryption equation do to the letter“P”?

Decryption Method: Shift Cipher

Definition (Decryption: Shift Cipher)

An English Language Shift Cipher

� + ∆ (mod 26) = �.

can be decrypted by undoing the shift ∆. Some letters will be easyto decrypt and some letters will wrap around the alphabet.

Decryption for an English Language Shift Cipher can be describedcompletely using modular arithmetic as

� +∇ (mod 26) = �,

where ∇ is a value so that ∇+ ∆ = 26.

Hail Caesar 7

Example (Hail Caesar 7)

Caesar has used so many different values of ∆ to make shiftciphers that he can’t remember how to decrypt!

If Caesar used ∆ = 12, what is ∇?

If Caesar used ∆ = 20, what is ∇?

Caesar remembers one shift cipher with ∇ = 24. What is ∆?

Caesar remembers one shift cipher with ∇ = 9. What is ∆?

In modular arithmetic, ∇ has a special name...

Related Idea: Additive Inverse

Definition (Additive Inverse)

The additive inverse for a (mod n) is a value a so that

a + a = 0 (mod n)

For English (or any Roman alphabet) Language, we will always

have∆ +∇ = 0 (mod 26).

If a Language has n letters, then we have

∆ +∇ = 0 (mod n).

From working with codes, we can understand that using theadditive inverse ∇ “really” works by moving all letters to the left∆ places.

Drill Time: Additive Inverse

Example (Drill Time: Additive Inverse)

Find the additive inverse for each of the following. Use yourcalculator to first simplify (if needed). Then find the number toadd that gets you up to n. Check your answers with a neighbor!

Find the additive inverse for 14 (mod 26).

Find the additive inverse for 19 (mod 26).

Find the additive inverse for 37 (mod 26).

Find the additive inverse for 14 (mod 16).

Find the additive inverse for 53 (mod 20).

Additive Inverses and Negatives

Example (Additive Inverses and Negatives)

Any time you see a negative sign (“–”) in modular arithmetic, itmeans “Find the additive inverse to whatever follows”. Answerthese related questions. Check your answers with a neighbor!

The quantity −4 (mod 10) means the additive inverse ofwhat?

Compute −4 (mod 10).

The quantity −9 (mod 16) means the additive inverse ofwhat?

Compute −9 (mod 16).

The quantity −14 (mod 26) means the additive inverse ofwhat?

Compute −14 (mod 16).

Drill Time: Simplifying Negatives

Example (Drill Time: Simplifying Negatives)

Simplify the following negative modular arithmetic quantities usingwhichever method you prefer. Check your answers with a neighbor!

Compute −4 (mod 15).

Compute −6 (mod 20).

Compute −23 (mod 10).

Compute −66 (mod 13).

Compute −100 (mod 27).

Compute −1000 (mod 37).

It’s Greek To Me

Example

Enemy agents have started to use different alphabets forencryption.

What would the encryption rule � + 9 = � do to the Greekletter ζ?

Write a modular arithmetic equation to represent a shiftcipher that sends α to κ?

It’s Greek To Me

Example

Enemy agents have started to use different alphabets forencryption.

If they use the equation � + 9 = � (mod 24) to encrypt,what will be the equation to decrypt?

If they use the equation � + 20 = � (mod 24) to encrypt,what will be the equation to decrypt?

It’s Greek To Me

Example

Enemy agents have started to use different alphabets forencryption.

If they use the equation � + 7 = � (mod 24) to encrypt,what are ∆ and ∇?

If they use a shift cipher that sends the letter “γ” to “τ”,what are ∆ and ∇?

Alien Invasion 1

! @ # $ % & ∅ Q ⊕ Σ Ψ

1 2 3 4 5 6 7 8 9 10 11

Example (Alien Invasion 1)

Aliens from Outer Space arrive on Earth. Despite having masteredinterstellar travel, they still use simple encryption techniques.Fortunately, the written symbols for their alien language are eerilyfamiliar.

Write the equation for the shift cipher that will encrypt theletter “@” as the letter Σ.

Write the decryption equation for the shift cipher above.

Alien Invasion 2

! @ # $ % & ∅ Q ⊕ Σ Ψ

1 2 3 4 5 6 7 8 9 10 11

Example (Alien Invasion 2)

The aliens have no idea how easy it is to break their code!

If they use the equation � + 7 = � (mod 11) to encrypt theirmessages, what are ∆ and ∇?

If they use a shift cipher that sends the letter “∅” to “#”,what are ∆ and ∇?

Alien Invasion 3

! @ # $ % & ∅ Q ⊕ Σ Ψ

1 2 3 4 5 6 7 8 9 10 11

Example (Alien Invasion 3)

The aliens detect that humans have been breaking their encryptedmessages. They frantically try to make the code moresophisticated by using larger shifts. Help humanity by answeringthe following. Check your answers with a nearby human neighbor!

What letter would 39 (mod 12) correspond to in thislanguage?

What letter would −39 (mod 12) correspond to in thislanguage?

Frequency Analysis and the Shift Cipher

Like the Caesar Cipher, a Shift Cipher disguises letters, but doesnot disguise the natural frequency of letters!

A B

C

D E

F

G

H I

JK

L M

N

O

P Q

R

S

TU

VW

X

Y

Z

The most frequent symbol used in the ciphertext will usuallycorrespond to the letter “E” in the (English) plaintext.In the example above, it appears that the ciphertext “C”corresponds to the plaintext “E,” so one might guess that thedecryption key is described by the equation

� + 2 = � (mod 26)

.

Shift Cipher Summary

The following table compares the Caesar and Shift Ciphers withrespect to encryption/decryption keys, key secrecy, and theireffects on letter frequency:

Encryption Decryption Key LetterCipher Key(s) Key(s) Secrecy FrequencyCaesar 3 23 Private Normal

Shift ∆ ∇ Private Normal

Despite the fact that the Shift Cipher has 25 possible keys, and theCaesar Cipher has only 1, each share the same two weaknesses:

1 They rely on the encryption and decryption keys being keptsecret: knowing either allows an enemy to decrypt and readyour message.

2 If an enemy does not know either of the keys, the cipher isstill vulnerable to frequency analysis: even a basic computercan count the number of times each letter appears in theciphertext. From this it is easy to find which letter stands infor “E,” and then we can find the decryption key.