Espionage Codebreaking: Mathematics of

Preview:

Citation preview

Codebreaking: Mathematics of Espionage

Duke TIP Academic Adventures

Petals Around the Rose

Third Person IntroductionsIntroduce the person sitting next you by saying the following.● Name

● Hometown

● Favorite Food

Human Machine

Rules and Expectations● Be Respectful● Participate● Don’t Talk When Someone Else Is● Don’t Shout Out Answers● Thinking > Answers● Have Fun

Finishing EarlyEveryone works at a different pace. If you happen to finish something early, please raise your hand and let me know. You may get to be my assistant!

Warm UpWhat does the following message say?

NVVK TVYUPUN

Warm Up

GOOD MORNING

What is Cryptography?• Cryptography is the practice and study of

techniques and algorithms for secure information.

• Like any field of study, cryptography comes with its own set of terminology.

Cryptography TerminologyPlaintext: message to be sent.Ciphertext: unintelligible text.Encryption: plaintext to ciphertext.Decryption: ciphertext to plaintext.Cipher: encryption and decryption.Key: used to encrypt and decrypt.Mono-alphabetic: letters are sent to exactly 1 letter.Poly-alphabetic: may send 1 letter to 2 or more letters.

Cryptography Preprocessing• All punctuation and spaces are removed and all

letters are capitalized. This is done so messages are more difficult to break.

• For example, consider:I need help! → INEEDHELP

Cryptography PreprocessingWords are then typically converted to strings of number using the following scheme.

Historical Overview

Historical Overview

Substitution CiphersA substitution cipher is a method of encrypting by which units of plaintext are replaced with ciphertext, according to a fixed system. We will consider the following three examples.● Pigpen Cipher● Atbash Cipher● Caesar Cipher

Pigpen Cipher

Pigpen Cipher1. Encrypt a message using the Pigpen cipher and

trade with a partner to decrypt their message.2. How could you figure out a message said if you

did not know the key?3. Do you think the Pigpen cipher provides a secure

way to send secret messages? How could you make it more secure?

Atbash Cipher

A B C D E F G H I J K L M

Z Y X W V U T S R Q P O N

Atbash Cipher1. Encrypt a message using the Atbash cipher and

trade with a partner to decrypt their message.2. How could you figure out a message said if you

did not know the key?3. Do you think the Atbash cipher provides a secure

way to send secret messages? Why or why not? How could you make it more secure?

Caesar Cipher

Caesar Cipher1. Create a cipher wheel.2. Encrypt a message using the Caesar cipher and trade with a partner

to decrypt their message (do not give them the key).3. How many different Caesar ciphers are there?4. Shifting by 29 is the same as shifting by what? Shifting by 37 is the

same as shifting by what? What is the relationship between these numbers?

5. What happens when you do a Caesar cipher more than once?6. Do you think the Caesar cipher provides a secure way to send

secret messages? Why or why not? How could you make it more secure?

Caesar Cipher● There are 26 distinct Caesar ciphers.

● Shifting by 29 is the same as shifting by 3 and shifting by 37 is the same as shifting by 11.

● If you do the Caesar cipher more than once, you simply add the keys together.

Substitution Cipher

Substitution Cipher1. Encrypt a message using a substitution cipher and trade with a partner to

decrypt their message.2. Are all Caesar ciphers also substitution ciphers? Are all substitution ciphers

also Caesar ciphers?3. How many different substitution ciphers are there?4. If a bad guy could test each substitution cipher in 1 second, what is the longest

amount of time it would take them to figure out what your message was?5. How many substitution ciphers would a bad guy have to test per second to

figure out the message to test all possible ciphers in 1 hour? Do you think this is possible?

6. Do you think substitution ciphers provide a secure way to send secret messages? Why or why not?

Substitution Cipher● A Caesar cipher is a substitution cipher, but a substitution

cipher is not necessarily a Caesar cipher.

● There are 26! = 4.0329146✕1026 different substitution ciphers.

● It would take 1.2788288✕1019 years.

● They would have to test 1.1202541 ✕ 1023 per second.

Lunch

Vigenere Cipher

Vigenere Cipher

Vigenere Cipher1. Encrypt a message using the Vigenere cipher and trade with a

partner to decrypt their message.2. Which cipher is more secure, the Caesar cipher or the Vigenere

cipher? Explain.3. How many possible Vigenere ciphers with a keyword of length 3

are there? Length 4? Length 5?4. Give an example of a Vigenere cipher that will give the same result

as using a Caesar cipher with 13 as the key.5. Suppose LETSGOPACK was encrypted using a Vigenere cipher

and the result was YGLMTQHUPM. What keyword was used?

Vigenere Cipher● Vigenere cipher is more secure, since it is polyalphabetic.

● There are 263 = 17,576 keywords of length 3, 264 = 456,976 keywords of length 4, and 265 = 11,881,376 keywords of length 5.

● N, NN, NNN, etc. would all result in shifting every letter 13.

● The keyword NCSU was used.

Introduction to Binary

Introduction to Binary1. Using the cards provided, represent the following

numbers.2. Represent your age, the day you were born, and

your shoe size using using the cards provided.3. What is the largest number you can represent

with five cards? Can you represent all whole numbers smaller than this number?

Introduction to BinaryThe largest number you can represent with 5 cards is 31 and each number less than 31 can also be represented using the cards.

Expanded Decimal NotationHow can we write the number 723 in expanded decimal notation?

Expanded Decimal NotationHow can we write the number 723 in expanded decimal notation?

723 = 7 ✕ 102 + 2 ✕ 101 + 3 ✕ 100

Decimal to Binary

Binary to Decimal

Binary AlphabetAs a class, will will convert the numbers 0 through 25 to binary so that we have a binary alphabet.

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

Binary AlphabetAs a class, will will convert the numbers 0 through 25 to binary so that we have a binary alphabet.

0 1 2 3 4 5 6 7 8 9 10 11 12

00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 01010 01011 01100

13 14 15 16 17 18 19 20 21 22 23 24 25

01101 01110 01111 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001

Logical Operators

AND OR XOR

XORWe typically use exclusive or in our everyday language. For example, if your meal comes with soup or salad, that means you either get soup or salad, but not neither soup or salad or not both soup and salad.

XORXOR (exclusive or) is an operation, ⨁, between the numbers 1 and 0 with the following properties.

● 1 ⨁ 1 = 0● 1 ⨁ 0 = 1● 0 ⨁ 0 = 0

XOR CipherWe can encrypt using the XOR cipher similar to how the Vigenere cipher works. Let’s say we wanted to encrypt the message DOG using the key 101101110111101.

XOR CipherFirst we need to convert DOG to binary by converting each letter to its respective binary representation.

D → 3 → 00011O → 14 → 01110G → 6 → 00110

So, DOG can be represented as 000110111000110.

XOR CipherWe then use the XOR operations between our plaintext and the key.

How would we decrypt this message?

0 0 0 1 1 0 1 1 1 0 0 0 1 1 0

⨁ 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1

1 0 1 0 1 1 0 0 1 1 1 1 0 1 1

XOR CipherWe decrypt the ciphertext by using the XOR operation again between the ciphertext and the key.

Why does this work?

1 0 1 0 1 1 0 0 1 1 1 1 0 1 1

⨁ 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1

0 0 0 1 1 0 1 1 1 0 0 0 1 1 0

XOR Cipher1. Encrypt a message using the XOR cipher and

trade with a partner to decrypt their message.2. How are the XOR and Vigenere ciphers similar?

How are they different?3. How many keys of length 3 are there? Length 4?

Length 5?4. What would happen if you used the same key

2017 times? 2018 times?

XOR Cipher● The XOR and Vigenere ciphers are both polyalphabetic, but

the XOR cipher has less possible keys.

● There are 23 = 8 keys of length 3, 24 = 16 keys of length 4, and 25 = 32 keys of length 5.

● Using the same key 2017 times would be the same as encrypting once and using the same key 2018 times would result in the plaintext.

Transposition CiphersA transposition cipher is a method of encryption by which the positions held by units of plaintext are shifted according to a regular system. We will consider the following three examples.● Column Transposition● Rail Fence Cipher● Route Cipher

Column TranspositionWEAREDISCOVEREDFLEEATONCEQKJEU

↓EVLNEWIREEESEAQACDTKDEECUROFOJ

1 2 3 4 5 6

W E A R E D

I S C O V E

R E D F L E

E A T O N C

E Q K J E U

5 1 2 3 6 4

E W E A D R

V I S C E O

L R E D E F

N E A T C O

E E Q K U J

Column Transposition1. Encrypt a message using the column

transposition cipher and trade with a partner to decrypt their message.

2. How could you figure out a message said if you did not know the key?

3. How many possible keys are there if 3 columns are used? 4 columns? 5 columns?

Column TranspositionThere are 3! = 6 keys for 3 columns, 4! = 24 keys for 4 columns, and 5! = 120 keys for 5 columns.

Rail Fence Cipher

DNETLEEDHESWLXFTAAX

D . N . . . E . . . T . . . L . .

. E . E . D . H . E . S . W L . X .

. . F . . . T . . . A . . . A . . . X

Rail Fence Cipher1. Encrypt a message using the rail fence cipher and

trade with a partner to decrypt their message.2. How could you figure out a message said if you

did not know the key?3. Do you think the rail fence cipher provides a

secure way to send secret messages? How could you make it more secure?

Route CipherWEAREDISCOVEREDFLEEATONCEJX

↓EJXCTEDECDAEWRIORFEONALEVSE

W R I O R F E O E

E E S V E L A N J

A D C E D E T C X

Route Cipher1. Encrypt a message using the route cipher and

trade with a partner to decrypt their message.2. How could you figure out a message said if you

did not know the key?3. Which cipher is more secure, the route cipher, the

rail fence cipher, or the column transposition cipher?

Scytale

Scytale1. Encrypt a message using a scytale and trade with

a partner to decrypt their message.2. How could you figure out a message said if you

did not know the key?3. Do you think encrypting messages using a

scytale is secure? How could you make it more secure?

Create a Cipher1. Create your own cipher that can be used to send

and receive secret messages.2. Is your cipher secure? Would you use it to send

private information? 3. Can your cipher be represented mathematically?4. How would explain your cipher to someone (who

knows nothing about cryptography) over the phone?

Cipher Presentations

Playfair Cipher

Playfair Cipher1. Encrypt a message using the Playfair cipher and

trade with a partner to decrypt their message.2. How could you figure out a message said if you

did not know the key?3. Do you think the Playfair cipher provides a

secure way to send secret messages? How could you make it more secure?

Steganography

Certificates and Evaluation1. Fill out the evaluation for Duke TIP.2. Write down what you liked and didn’t like about

the class on a blank sheet of paper.3. Receive your certificate.4. Celebrate!