You are currently browsing the tag archive for the ‘codes’ tag.

elliptical1

If you are a teacher then please also visit my new site: intermathematics.com for over 2000+ pdf pages of resources for teaching IB maths!

Elliptical Curve Cryptography

Elliptical curves are a very important new area of mathematics which have been greatly explored over the past few decades.  They have shown tremendous potential as a tool for solving complicated number problems and also for use in cryptography.

Andrew Wiles, who solved one of the most famous maths problems of the last 400 years, Fermat’s Last Theorem, using elliptical curves.  In the last few decades there has also been a lot of research into using elliptical curves instead of RSA encryption to keep data transfer safe online.  So, what are elliptical curves?  On a simple level they can be regarded as curves of the form:

y² = x³ +ax + b

elliptical1

If we’re being a bit more accurate, we also need 4a³ + 27b² ≠ 0.  This stops the graph having “singular points” which cause problems with the calculations.  We also have a “point at infinity” which can be thought of as an extra point added on to the usual x,y plane representing infinity.  This also helps with calculations – though we don’t need to go into this in any more detail here!

Addition of two points A and B

What makes elliptical curves so useful is that we can create a group structure using them.  Groups are very important mathematical structures because of their usefulness in being applied to problem solving.  A group needs to have certain properties.  For example, we need to be able to combine 2 members of the group to create a 3rd member which is also in the group.  This is how it is done with elliptical curves:

elliptical2

Take 2 points A and B on y² = x³ -4x + 1.  In the example we have A = (2,1) and B = (-2,-1).   We now want to find an answer for A + B which also is on the elliptical curve.  If we add them as we might vectors we get (0,2) – but unfortunately this is not on the curve.  So, we define the addition A + B through the following geometric steps.

elliptical3

We join up the points A and B.  This line intersects the curve in one more place, C.

elliptical4

We then reflect the point C in the x axis. We then define this new point C’ = A + B.  In this case this means that (2,1) + (-2,-1) = (1/4, -1/8).

Addition of 2 points when A = B

We have to also be able to cope with the situation when the point A and B are the same.   Here we create the line through A which is the tangent to the curve at that point:

We then use the same transformation as before to say that A+B = C’.  For example with the curve y² = x³ -12x, if we start with the point A(-2,4) then this transformation tells us that A + A = (4,-4).

Elliptical curves over finite fields

For the purposes of cryptography we often work with elliptical curves over finite fields.  This means we (say) only consider integer coordinate solutions and work in modulo arithmetic (mod prime).

Say we start with the curve y² = x³ +x+1, and just look at the positive integer solutions mod 7.  (Plotted using the site here).

When x = 1,

y² = 1³ +1 + 1

y² = 3

So this has no integer solution.

Next, when x  = 2 we have:

y² = 2³ +2 +1 = 11.

However when we are working mod 7 we look at the remainder when 11 is divided by 7 (which is 4).  So:

y² = 4 (mod 7)

y = 2 or y = -2  = 5 (mod 7)

When x = 3 we have:

y² = 3³ +3 +1 = 31

y² = 3 (mod 7)

which has no integer solutions.

In fact, all the following coordinate points satisfy the equation (mod 7):

(2,2), (0,1), (0,6), (2,5).

Addition under modulo arithmetic

Let’s look at the coordinate points we calculated before for the elliptical curve y² = x³ +x+1 (integers solutions and mod 7) – they form a group under addition.  (Table generated here)

In order to calculate addition of points when dealing with elliptical curves with integer points mod prime we use the same idea as expressed above for general graphs.

The table tells us that (0,1) + (0,1) = (2,5).  If we were doing this from the graph we would draw the tangent to the curve at (0,1), find where it intersects the graph again, then reflect this point in the x axis.  We can do all this algebraically.

First we find the gradient of the tangent when x = 0:

Next we have to do division modulo 7 (you can use a calculator here, and you can also read more about division modulo p here).

Next we find the equation of the tangent through (0,1):

Next we find where this tangent intersects the curve again (I used Wolfram Alpha to solve this mod 7)

We then substitute the value x = 2 into the original curve to find the y coordinates:

(2,2) is the point where the tangent would touch the curve and (2,5) is the equivalent of the reflection transformation.  Therefore our answer is (2,5).  i.e (0,1) + (0,1) = (2,5) as required.

When adding points which are not the same we use the same idea – but have to find the gradient of the line joining the 2 points rather than the gradient of the tangent.  We can also note that when we try and add points such as (2,5) and (2,2) the line joining these does not intersect the graph again and hence we affix the point an infinity as (2,5) + (2,2).

Using elliptical codes for cryptography

Even though all this might seem very abstract, these methods of calculating points on elliptical curves form the basis of elliptical cryptography.  The basic idea is that it takes computers a very long time to make these sorts of calculations – and so they can be used very effectively to encrypt data.

Say for example two people wish to create an encryption key.

They decide on an elliptical curve and modulo. Let’s say they decide on y² = x³ +x+1 for integers, mod 7.

This creates the addition group

Next they choose a point of the curve.  Let’s say they choose P(1,1).

Person 1 chooses a secret number n and then sends nP (openly).  So say Person 1 chooses n = 2.  2(1,1) = (1,1) + (1,1) = (0,2).  Person 1 sends (0,2).

Person 2 chooses a secret number m and then sends mP (openly).  So say Person 2 chooses m = 3.  3(1,1) = (1,1) + (1,1) + (1,1) = (0,2) + (1,1) = (0,5).  Person 2 sends (0,5).

Both Person 1 and Person 2 can easily calculate mnP (the secret key).

Person 1 receives (0,5) and so does 2(0,5) = (0,5) + (0,5) = (1,1).  This is the secret key.

Person 2 receives (0,2) and so does 3(0,2) = (0,2) + (0,2) +(0,2) = (1,1).  This is the same secret key.

But for a person who can see mP and nP there is no quick method for working out mnP – with a brute force approach extremely time consuming. Therefore this method can be successfully used to encrypt data.

Essential Resources for IB Teachers

1) Intermathematics.com

Screen Shot 2021-08-21 at 1.07.49 PM

If you are a teacher then please also visit my new site.  This has been designed specifically for teachers of mathematics at international schools.  The content now includes over 2000 pages of pdf content for the entire SL and HL Analysis syllabus and also the SL Applications syllabus.  Some of the content includes:

  1. Original pdf worksheets (with full worked solutions) designed to cover all the syllabus topics.  These make great homework sheets or in class worksheets – and are each designed to last between 40 minutes and 1 hour.
  2. Original Paper 3 investigations (with full worked solutions) to develop investigative techniques and support both the exploration and the Paper 3 examination.
  3. Over 150 pages of Coursework Guides to introduce students to the essentials behind getting an excellent mark on their exploration coursework.
  4. A large number of enrichment activities such as treasure hunts, quizzes, investigations, Desmos explorations, Python coding and more – to engage IB learners in the course.

There is also a lot more.  I think this could save teachers 200+ hours of preparation time in delivering an IB maths course – so it should be well worth exploring!

Essential Resources for both IB teachers and IB students

1) Exploration Guides and Paper 3 Resources

Screen Shot 2021-12-01 at 1.19.14 PM

I’ve put together a 168 page Super Exploration Guide to talk students and teachers through all aspects of producing an excellent coursework submission.  Students always make the same mistakes when doing their coursework – get the inside track from an IB moderator!  I have also made Paper 3 packs for HL Analysis and also Applications students to help prepare for their Paper 3 exams.  The Exploration Guides can be downloaded here and the Paper 3 Questions can be downloaded here.

Elliptical Curve Cryptography

This post builds on some of the ideas in the previous post on elliptical curves. This blog originally appeared in a Plus Maths article I wrote here.  The excellent Numberphile video above expands on some of the ideas below.

On a (slightly simplified) level elliptical curves they can be regarded as curves of the form:

y² = x³ +ax + b

So for example the curve below is an elliptical curve.  This curve also has an added point at infinity though we don’t need to worry about that here.  Elliptical curve cryptography is based on the difficulty in solving arithmetic problems on these curves.  If you remember from the last post, we have a special way of defining the addition of 2 points.

elliptical1

Let’s say take 2 points A and B on y² = x³ -4x + 1. In the example we have A = (2,1) and B = (-2,1). We now want to find an answer for A + B which also is on the elliptical curve. If we add them as we might vectors we get (0,2) – but unfortunately this is not on the curve. So, we define the addition A + B through the following geometric steps.

elliptical3

We join up the points A and B. This line intersects the curve in one more place, C.

elliptical4

We then reflect the point C in the x axis. We then define this new point C’ = A + B. In this case this means that (2,1) + (-2,1) = (1/4, -1/8).

Trying another example, y² = x³ -5x + 4 (below), with A = (1,0) and B = (0,2) we have C = (3,-4) and C’ = (3,4). Therefore (1,0) + (0,2) = (3,4).

elliptical5

We also need to have a definition when A and B define the same point on the curve. This will give us the definition of 2A.  In this case we take the tangent to the curve at that point, and then as before find the intersection of this line and the curve, before reflecting the point.  This probably is easier to understand with another graph:

elliptical10

Here we used the graph y² = x³ -5x + 4 again.  This time point A = B = (-1.2, 2.88) and we have drawn the tangent to the curve at this point, which gives point D, which is then reflected in the x axis to give D’. D’ = (2.41, -2.43).  Therefore we can say 2A = D’, or 2(-1.2, 2.88) = (2.41, -2.43).

Now addition of points is defined we can see how elliptical curve cryptography works.  The basic idea is that given 2 points on the curve, say A and B, it takes a huge amount of computing power to work out the value a such that aA = B.  For example, say I use the curve y² = x³ -25x to encrypt, and the 2 points on the curve are A = (-4,6) and B = (1681/144 , -62279/1728).  Someone who wanted to break my encryption would need to find the value a such that a(-4,6) = (1681/144 , -62279/1728).   The actual answer is a =2 which we can show graphically.  As we want to show that 2(-4,6) = (1681/144 , -62279/1728) , we can use the previous method of finding the tangent at the point (-4,6):

elliptical12

We can then check with Geogebra which shows that B’ is indeed (1681/144 , -62279/1728).  When a is chosen so that it is very large, this calculation becomes very difficult to attack using brute force methods – which would require checking 2(4,-6), 3(4,-6), 4(4,-6)… until the solution (1681/144 , -62279/1728) was found.

elliptical14

NSA and hacking data

Elliptical curve cryptography has some advantages over RSA cryptography – which is based on the difficulty of factorising large primes – as less digits are required to create a problem of equal difficulty.  Therefore data can be encoded more efficiently (and thus more rapidly) than using RSA encryption.  Currently the digital currency Bitcoin uses elliptical curve cryptography, and it is likely that its use will become more widespread as more and more data is digitalised.  However, it’s worth noting that as yet no-one has proved that it has to be difficult to crack elliptical curves – there may be a novel approach which is able to solve the problem in a much shorter time.  Indeed many mathematicians and computer scientists are working in this field.

Government digital spy agencies like the NSA and GCHQ are also very interested in such encryption techniques.  If there was a method of solving this problem quickly then overnight large amounts of encrypted data would be accessible – and for example Bitcoin currency exchange  would no longer be secure.  It also recently transpired that the NSA has built “backdoor” entries into some elliptical curve cryptography algorithms which have allowed them to access data that the people sending it thought was secure.   Mathematics is at the heart of this new digital arms race.

If you enjoyed this post you might also like:

RSA Encryption – the encryption system which secures the internet.

Circular inversion – learn about some other geometrical transformations used in university level mathematics.

code2

Crypto Analysis to Crack Vigenere Ciphers

(This post assumes some familiarity with both Vigenere and Ceasar Shift Ciphers.  You can do some background reading on them here first).

We can crack a Vigenere Cipher using mathematical analysis.  Vigenere Ciphers are more difficult to crack than Caesar Shifts, however they are still susceptible to mathematical techniques.  As an example, say we receive the code:

VVLWKGDRGLDQRZHSHVRAVVHZKUHRGFHGKDKITKRVMG

If we know it is a Vigenere Cipher encoded with the word CODE then we can create the following decoding table.

VIGENERE4

Here we have 4 alphabets, each starting with the letters of the code word.  To decode we cycle through the alphabets.  The first code letter is V so we find this in the C row and then look at the letter at the top of the column – this is T.  This is our first letter.  Next the second code letter is also V, but this time we find it the O row.  The column letter corresponding to this is H.  We continue this method which gives the decoded sentence:

THIS IS AN EXAMPLE OF HOW THE VIGENERE CIPHER WORKS

How do we know what cipher to use? 

In any kind of crypto-analyis we need to decide which technique has been used.  Say for example we receive the message:

GZEFWCEWTPGDRASPGNGSIAWDVFTUASZWSFSGRQOHEUFLAQVTUWFV
JSGHRVEEAMMOWRGGTUWSRUOAVSDMAEWNHEBRJTBURNUKGZIFOHR
FYBMHNNEQGNRLHNLCYACXTEYGWNFDRFTRJTUWNHEBRJ

In real code breaking we won’t have a message alongside it saying, “Use a Vigenere Cipher.”  A large part of the skill of code breaking is deciding which encoding technique has been used.  For our received message we have the frequency:

VINEGERE7

So, in this case is it best to do look for a Caesar Shift or a Vigenere Cipher?  To find this out, we could do with finding out how “smooth” the bar chart is and how it compares with the expected frequencies.  The expected values in English are:

vigenere3

A Caesar Shift simply shifts every letter in the message by a given number of letters in the alphabet, so we would expect a frequency barchart for a Caesar Shift to have the same peaks and troughs (just shifted along).  The Vigenere makes frequency analysis more difficult because it “smooths out” the frequencies – this means that the bar chart for the frequency will be less spiky and more uniform.

Incidence of Coincidence

A mathematical method to check how smooth the bar chart is, is to use the Incidence of Coincidence – this method is outlined in this post on Practical Cryptography, and uses this formula:

VIGENERE5

There is also a script on the site to work out the I.C for us.  If we enter our received code we get an I.C of 0.045.  We would expect an I.C of around 0.067 for a regular distribution of English letters (which we would find in a Caesar Shift for example).  Therefore this I.C value is a clue that we have a Vigenere Cipher rather than a Caesar shift.

Exploiting the cyclic nature of the Vigenere Cipher

So, we suspect it is a Vigenere Cipher, next we want to find out what the code word that was used to generate the code table is.  To do this we can look at the received code for repeating groups of letters.   There is a cyclic nature to the Vigenere Cipher, so there will also be a cyclic nature to the encoded message.

Using the site Crypto Corner we can analyse the text for repeating patterns of letters.  This gives us:

VINEGER8

This clearly indicates that there are a lot of letters repeating with period of 3.  Therefore it is a good guess that the keyword is also length 3.

So, next we can split the received message into 3 separate messages:

GFEPRPGAVUZFRHFQUVGVAOGURADEHRBNGFRBNQRNYXYNRRUHR
ZWWGAGSWFAWSQELVWJHEMWGWUVMWEJUUZOFMNGLLATGFFJWEJ
ECTDSNIDTSSGOUATFSREMRTSOSANBTRKIHYHENHCCEWDTTNB

Here we have simply generated the first line by taking the first, fourth, seventh, tenth etc. letters.

Cracking the code

Now we can do three separate Cesar Shift tests on these separate lines:

The first line has frequency:

vigg1

which strongly suggests that R in the cipher text is going to E.  This gives us the following Caesar Shift:

vigenere10

The second line has the following frequency:

VINEGER11

Which strongly suggests that W in the cipher text is going to E.  This gives us:

vigenere11

Lastly we notice that this will give us the codeword NS_.  Well NSA, (the American digital spy agency) would be a good guess so for the third Caesar Shift we try:

vigg2

Putting these together we have the Vigenere Cipher:

vigg3

and this decodes our received code as:

THE SECRET CODE IS CONTAINED IN THIS MESSAGE.  YOU MUST ADD THE FIRST PRIME NUMBER TO THE SECOND SQUARE NUMBER TO CRACK THIS. WHEN YOU HAVE DONE THAT CLICK BELOW AND ENTER THE NUMBER.

We have done it!  We have cracked the Vigenere Cipher using a mixture of statistics, logic and intuition.  The method may seem long, but this was a cipher that was thought to be unbreakable – and indeed took nearly 300 years to crack.  Today, using statistical algorithms it can be cracked in seconds.  Codes have moved on from the Vigenere Cipher – but maths remains at the heart of both making and breaking them.

If you enjoyed this post you might also like:

The Maths Code Challenge – three levels of codes to attempt, each one providing a password to access the next code in the series.  Can you make it onto the leaderboard?

RSA public key encryption – the code that secures the internet.

Essential resources for IB students:

1) Exploration Guides and Paper 3 Resources

Screen Shot 2021-05-19 at 6.32.13 PM

I’ve put together four comprehensive pdf guides to help students prepare for their exploration coursework and Paper 3 investigations. The exploration guides talk through the marking criteria, common student mistakes, excellent ideas for explorations, technology advice, modeling methods and a variety of statistical techniques with detailed explanations. I’ve also made 17 full investigation questions which are also excellent starting points for explorations.  The Exploration Guides can be downloaded here and the Paper 3 Questions can be downloaded here.

gchq

GCHQ – the British cyber spy agency – have had a rough few months following some staggering revelations from Edward Snowden, so they’re doing some positive PR at the moment to highlight the importance of mathematics and computing skills in code-breaking.  There are 4 codes to solve (the first one posted above) – each answer leading on an internet treasure-hunt to the next clue.  Those who can solve all 4 clues stand a chance of winning a Google Nexus and Raspberry Pi – and possibly could lead to a job opportunity with GCHQ.

The competition started two days ago (10th September) – and there is a six week deadline to solve all clues.  So, get cracking!

If you liked this post you might also like:

Cracking Codes Lesson. An example of 2 double period lessons on code breaking

Cracking ISBN and Credit Card Codes. The mathematics behind ISBN codes and credit card codes

isbn

Cracking ISBN and Credit Card Codes

ISBN codes are used on all books published worldwide. It’s a very powerful and useful code, because it has been designed so that if you enter the wrong ISBN code the computer will immediately know – so that you don’t end up with the wrong book. There is lots of information stored in this number. The first numbers tell you which country published it, the next the identity of the publisher, then the book reference.

Here is how it works:

Look at the 10 digit ISBN number. The first digit is 1 so do 1×1. The second digit is 9 so do 2×9. The third digit is 3 so do 3×3. We do this all the way until 10×3. We then add all the totals together. If we have a proper ISBN number then we can divide this final number by 11. If we have made a mistake we can’t. This is a very important branch of coding called error detection and error correction. We can use it to still interpret codes even if there have been errors made.
If we do this for the barcode above we should get 286. 286/11 = 26 so we have a genuine barcode.

Check whether the following are ISBNs

1) 0-13165332-6
2) 0-1392-4191-4
3) 07-028761-4

Challenge (harder!) :The following ISBN code has a number missing, what is it?
1) 0-13-1?9139-9

Answers in white text at the bottom, highlight to reveal!

Credit cards use a different algorithm – but one based on the same principle – that if someone enters a digit incorrectly the computer can immediately know that this credit card does not exist.  This is obviously very important to prevent bank errors.  The method is a little more complicated than for the ISBN code and is given below from computing site Hacktrix:

creditcard2credit card 4creditcard3credit card 6credit card 5credit card 8credit card 7

credi card 9 You can download a worksheet for this method here. Try and use this algorithm to validate which of the following 3 numbers are genuine credit cards:

1) 5184 8204 5526 6425

2) 5184 8204 5526 6427

3) 5184 8204 5526 6424

Answers in white text at the bottom, highlight to reveal!


ISBN:
1) Yes
2) Yes
3) No
1) 3 – using x as the missing number we end up with 5x + 7 = 0 mod 11. So 5x = 4 mod 11. When x = 3 this is solved.
Credit Card: The second one is genuine

If you liked this post you may also like:

NASA, Aliens and Binary Codes from the Stars – a discussion about how pictures can be transmitted across millions of miles using binary strings.

Cracking Codes Lesson – an example of 2 double period lessons on code breaking.

Essential resources for IB students:

1) Exploration Guides and Paper 3 Resources

Screen Shot 2021-05-19 at 6.32.13 PM

I’ve put together four comprehensive pdf guides to help students prepare for their exploration coursework and Paper 3 investigations. The exploration guides talk through the marking criteria, common student mistakes, excellent ideas for explorations, technology advice, modeling methods and a variety of statistical techniques with detailed explanations. I’ve also made 17 full investigation questions which are also excellent starting points for explorations.  The Exploration Guides can be downloaded here and the Paper 3 Questions can be downloaded here.

code

Code breaking is a good activity to introduce problem solving skills and real world careers for mathematicians. 

Code Cracking worksheets

Marcus De Satouy video explaining codes

Counton website to generate different codes

Nice Morse Code Generator

Numberphile also have a good introduction to public key encryption using prime numbers.

Website Stats

  • 9,480,431 views

About

All content on this site has been written by Andrew Chambers (MSc. Mathematics, IB Mathematics Examiner).

New website for International teachers

I’ve just launched a brand new maths site for international schools – over 2000 pdf pages of resources to support IB teachers.  If you are an IB teacher this could save you 200+ hours of preparation time.

Explore here!

Free HL Paper 3 Questions

P3 investigation questions and fully typed mark scheme.  Packs for both Applications students and Analysis students.

Available to download here

IB Maths Super Exploration Guide

A Super Exploration Guide with 168 pages of essential advice from a current IB examiner to ensure you get great marks on your coursework.

Available to download here.

Recent Posts

Follow IB Maths Resources from Intermathematics on WordPress.com