spring 2015 codes lecture 2: the caesar & shift...

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

Upload: phamkhue

Post on 30-Mar-2018

215 views

Category:

Documents


1 download

TRANSCRIPT

Cryptography

Codes Lecture 2: The Caesar & Shift CiphersSpring 2015

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!

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

Example

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

Example

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) OR by moving 23 units to the right. Forthe letters A, B, C this decryption can be described using the rule

� + 23 = �.

Decryption for the Caesar Cipher can be described completelyusing modular arithmetic as

� + 23 (mod 26) = �.

Hail Caesar

Example

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 English uses some letters more frequently than 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!The graph below indicates the relative frequency of letters in theEnglish language when encrypted by the Caesar Cipher.

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 the Caesar Cipher whenencrypting and decrypting English language plaintext.

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

Hail Caesar

Example

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

Example

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

Example

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

Example

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 the language of 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 language which uses the Roman alphabet), we

will always have∆ +∇ = 0 (mod 26).

If a language has n letters, then we have

∆ +∇ = 0 (mod n).

Note

You have seen additive inverses before! In standard (non-modular)arithmetic, the additive inverse of a is −a, since a + (−a) = 0.

Drill Time: Additive Inverse

Example

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

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 of...?

Compute (simplify) −4 (mod 10).

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

Compute −9 (mod 16).

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

Compute −14 (mod 26).

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

Compute −26 (mod 14).

Drill Time: Simplifying Negatives

Example

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 using different alphabets for encryption!

What would the encryption rule � + 13 = � 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 using different alphabets for encryption!

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 decrypt,what will be the equation to encrypt?

It’s Greek To Me

Example

Enemy agents have started using different alphabets for encryption!

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

! @ # $ % & ∅ Q ⊕ Σ Ψ

1 2 3 4 5 6 7 8 9 10 11

Example

An alien species arrives on Earth. Despite having masteredinterstellar travel, they still use simple encryption techniques.Fortunately, the written symbols for their alien language are eerilyfamiliar.

Write the modular equation for the shift cipher that willencrypt the letter “@” as the letter Σ.

Write the decryption equation for the shift cipher above.

Alien Invasion

! @ # $ % & ∅ Q ⊕ Σ Ψ

1 2 3 4 5 6 7 8 9 10 11

Example

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

! @ # $ % & ∅ Q ⊕ Σ Ψ

1 2 3 4 5 6 7 8 9 10 11

Example

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.