# Can You Break Julius Caesar’s Cryptosystem?

Can You Break Julius Caesar’s Cryptosystem?

In this module, students will be introduced to encryption and decryption by exploring Julius Caesar’s method of shifting letters in the alphabet.

Appropriate for ages

11+.

Allow 55 minutes to complete the module.Important note:

This module should be led by an instructor with basic Wolfram Language knowledge. If you would like to learn the language, please try this. If you would like a Computational Thinking Initiative ambassador or volunteer to help you run an adventure, please .

Appropriate for ages

11+.

Allow 55 minutes to complete the module.Important note:

This module should be led by an instructor with basic Wolfram Language knowledge. If you would like to learn the language, please try this

Learning Objective

◼

Students will understand how the Caesar cryptosystem encrypts messages and, based on this understanding, devise a method for decryption

Computational Thinking Principles and Practices

◼

Exploring entire categories all at once (i.e. look at all flags, all of Shakespeare’s sonnets, etc.)

◼

Simulating things that are hard or impossible to do by performing real-world experiments

◼

Treating the computer’s “misunderstandings” as proxies for one’s own

Standards Alignment

◼

AP Computer Science Principles:

◼

LO 1.1.1: apply a creative development process when creating computational artifacts

◼

LO 1.2.5: analyze the correctness, usability, functionality and suitability of computational artifacts

◼

LO 3.1.1: find patterns and test hypotheses about digitally processed information to gain insight and knowledge

◼

LO 4.1.1: develop an algorithm for implementation in a program

◼

CSTA K–12 Computer Science Standards:

◼

Level 3A CPP 9: explain the principles of security by examining encryption, cryptography and authentication technique

Helpful Background

◼

Information on Caesar ciphers:

## STARTING POINT

STARTING POINT

“Today we’re going to take a look at Julius Caesar’s cryptosystem, sometimes called the Caesar cipher. Let’s start by looking at the alphabet. Simply type Alphabet[] and press +.”

In[1]:=

Alphabet[]

Out[1]=

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

“Every letter in the alphabet has a position.”

In[2]:=

LetterNumber[Alphabet[]]

Out[2]=

{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,26}

In[3]:=

LetterNumber["d"]

Out[3]=

4

“In much the same way, we can go from numbers to letters.”

You may need to explain Range here.

In[4]:=

Range[26]

Out[4]=

{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,26}

In[5]:=

FromLetterNumber[Range[26]]

Out[5]=

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

In[6]:=

FromLetterNumber[4]

Out[6]=

d

◼ Try a number larger than 26 and ask, “Why is there a missing symbol there?”

◼ Are there other numbers we can't use with FromLetterNumber?

◼ Other than letters, what might appear in a message you would want to encode?

◼ If students are curious about the syntax for lists, try showing some list functions like First or Part and explaining that using a standard syntax lets us find pieces of the list.

CHECKPOINT

Check to see if everyone understands that letters have a position.

“We can also apply LetterNumber to a word.”

In[7]:=

LetterNumber["cat"]

Out[7]=

{3,1,20}

In[8]:=

FromLetterNumber[{3,1,20}]

Out[8]=

{c,a,t}

“That doesn’t look like the word we started with. We ended up with a list of letters instead of a single word. Let’s use StringJoin to combine them.”

In[9]:=

StringJoin[FromLetterNumber[{3,1,20}]]

Out[9]=

cat

◼ Try some other words.

◼ What is your name in numbers?

◼ Change your word to numbers, share the numbers with your neighbor and have them change it back to a word. Was it the word you started with?

CHECKPOINT

Check to see if students are comfortable switching between words and numbers.

“Julius Caesar used letter positions to encrypt messages. Caesar’s cryptosystem works by shifting the position of each letter in the alphabet. One way to do this is to just add three, or some other number, to each position.”

In[10]:=

LetterNumber["cat"]

Out[10]=

{3,1,20}

In[11]:=

{3,1,20}+3

Out[11]=

{6,4,23}

In[12]:=

FromLetterNumber[{6,4,23}]

Out[12]=

{f,d,w}

In[13]:=

StringJoin[FromLetterNumber[{6,4,23}]]

Out[13]=

fdw

“In this case, we call ‘fdw’ the encrypted version of ‘cat.’”

◼ Try some other words.

◼ Change your word to numbers, shift over the letters by adding, share the numbers with your neighbor and have them change those numbers back to a word. Was it the word you started with?

◼ “You have just encrypted!”

◼ Some students may already notice the issue with shifting Z. A discussion should be encouraged.

CHECKPOINT

Check to see if students understand the concept of shifting the position of the letters in the alphabet.

“But what happens if we try to shift the position of Z, even just by one?”

In[14]:=

LetterNumber["z"]+1

Out[14]=

27

In[15]:=

FromLetterNumber[27]

Out[15]=

Missing[NotApplicable]

“Or what if we want to do a series of words? What will happen to the white spaces?”

In[16]:=

LetterNumber["keep calm and code on"]

Out[16]=

{11,5,5,16,Missing[NotApplicable],3,1,12,13,Missing[NotApplicable],1,14,4,Missing[NotApplicable],3,15,

4,5,Missing[NotApplicable],15,14}

“We have two problems here: we’re running out of alphabet, and we don’t have a way to deal with spaces. Let’s focus on the first problem: how can we get another letter by shifting Z?”

◼ If students suggest shifting downward instead of upward, try the code using subtraction instead of addition. Try a word that includes A to demonstrate the problem.

◼ If students suggest shifting only Z downward, ask, "Will this create any problems?" Demonstrate that with a shift by one, both X and Z would be encrypted as Y, so the person decrypting the message wouldn't be able to tell the difference between the two letters.

◼ If we shifted all of the letters up by one, would any of them become the letter A?

◼ What would happen if we wrote our letters as a circle instead of a line?

CHECKPOINT

Check that students understand the need to connect the end of the alphabet to the beginning.

“Let's take a look at the function RotateLeft.”

In[17]:=

RotateLeft[Alphabet[],3]

Out[17]=

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

“It’s helpful to see which letter went where, so to speak. We should make rules for what letter becomes what.”

In[18]:=

Thread[Alphabet[]RotateLeft[Alphabet[],3]]

Out[18]=

{ad,be,cf,dg,eh,fi,gj,hk,il,jm,kn,lo,mp,nq,or,ps,qt,ru,sv,

tw,ux,vy,wz,xa,yb,zc}

◼ Students who are more math inclined may want to try Mod.

◼ Try changing the value of 3 (3 was Julius Caesar’s personal favorite number).

◼ Try RotateRight instead.

◼ It may help to demonstrate that you could rewrite LetterNumber or FromLetterNumber as replacement rules.

CHECKPOINT

Check with students to see if they understand replacement rules.

“Now that we have replacement rules, we need a function that actually does replace the letters in a word.”

In[19]:=

StringReplace["cat",Thread[Alphabet[]RotateLeft[Alphabet[],3]]]

Out[19]=

fdw

“Look familiar? Let’s check and see if our new method works with white spaces.”

In[20]:=

StringReplace["keep calm and code on",Thread[Alphabet[]RotateLeft[Alphabet[],3]]]

Out[20]=

nhhs fdop dqg frgh rq

“It looks like we solved the white space problem too.