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

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

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:

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.

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

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

Revision Village has been put together to help IB students with topic revision both for during the course and for the end of Year 12 school exams and Year 13 final exams. I would strongly recommend students use this as a resource during the course (not just for final revision in Y13!) There are specific resources for HL and SL students for both Analysis and Applications.

There is a comprehensive Questionbank takes you to a breakdown of each main subject area (e.g. Algebra, Calculus etc) and then provides a large bank of graded questions. What I like about this is that you are given a difficulty rating, as well as a mark scheme and also a worked video tutorial. Really useful!

The Practice Exams section takes you to a large number of ready made quizzes, exams and predicted papers. These all have worked solutions and allow you to focus on specific topics or start general revision. This also has some excellent challenging questions for those students aiming for 6s and 7s.

**Essential Resources for IB Teachers**

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:

**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.**Original Paper 3 investigations**(with full worked solutions) to develop investigative techniques and support both the exploration and the Paper 3 examination.- Over 150 pages of
**Coursework Guides**to introduce students to the essentials behind getting an excellent mark on their exploration coursework. - 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

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.

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.

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

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

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:

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

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.

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

**IB Revision**

If you’re already thinking about your coursework then it’s probably also time to start planning some revision, either for the end of Year 12 school exams or Year 13 final exams. There’s a really great website that I would strongly recommend students use – you choose your subject (HL/SL/Studies if your exam is in 2020 or Applications/Analysis if your exam is in 2021), and then have the following resources:

The Questionbank takes you to a breakdown of each main subject area (e.g. Algebra, Calculus etc) and each area then has a number of graded questions. What I like about this is that you are given a difficulty rating, as well as a mark scheme and also a worked video tutorial. Really useful!

The Practice Exams section takes you to ready made exams on each topic – again with worked solutions. This also has some harder exams for those students aiming for 6s and 7s and the Past IB Exams section takes you to full video worked solutions to every question on every past paper – and you can also get a prediction exam for the upcoming year.

I would really recommend everyone making use of this – there is a mixture of a lot of free content as well as premium content so have a look and see what you think.

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

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:

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:

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:

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:

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:

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

The second line has the following frequency:

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

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:

Putting these together we have the Vigenere Cipher:

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:

Revision Village has been put together to help IB students with topic revision both for during the course and for the end of Year 12 school exams and Year 13 final exams. I would strongly recommend students use this as a resource during the course (not just for final revision in Y13!) There are specific resources for HL and SL students for both Analysis and Applications.

There is a comprehensive Questionbank takes you to a breakdown of each main subject area (e.g. Algebra, Calculus etc) and then provides a large bank of graded questions. What I like about this is that you are given a difficulty rating, as well as a mark scheme and also a worked video tutorial. Really useful!

The Practice Exams section takes you to a large number of ready made quizzes, exams and predicted papers. These all have worked solutions and allow you to focus on specific topics or start general revision. This also has some excellent challenging questions for those students aiming for 6s and 7s.

Each course also has a dedicated video tutorial section which provides 5-15 minute tutorial videos on every single syllabus part – handily sorted into topic categories.

2) Exploration Guides and Paper 3 Resources

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

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

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:

Revision Village has been put together to help IB students with topic revision both for during the course and for the end of Year 12 school exams and Year 13 final exams. I would strongly recommend students use this as a resource during the course (not just for final revision in Y13!) There are specific resources for HL and SL students for both Analysis and Applications.

There is a comprehensive Questionbank takes you to a breakdown of each main subject area (e.g. Algebra, Calculus etc) and then provides a large bank of graded questions. What I like about this is that you are given a difficulty rating, as well as a mark scheme and also a worked video tutorial. Really useful!

The Practice Exams section takes you to a large number of ready made quizzes, exams and predicted papers. These all have worked solutions and allow you to focus on specific topics or start general revision. This also has some excellent challenging questions for those students aiming for 6s and 7s.

Each course also has a dedicated video tutorial section which provides 5-15 minute tutorial videos on every single syllabus part – handily sorted into topic categories.

2) Exploration Guides and Paper 3 Resources

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 breaking is a good activity to introduce problem solving skills and real world careers for mathematicians.

Marcus De Satouy video explaining codes

Counton website to generate different codes

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