RSA- Democratising Privacy
An exploration of how the mathematics behind the RSA cryptosystem enables the global use of encryption with its basis in modular arithmetic and its roots in public key encryption while offering extraordinary security.
Table of Contents:
• Glossary
• Introduction
• RSA Encryption and Decryption
• Real World Example
• Why does it work
♣ Fermat´s Little Theorem
• Proof
♣ Euler Theorem
♣ Chinese Remainder Theorem
• Conclusion
• Appendix
♣ Proof of modulus
♣ Sources
♣ Bibliography
Glossary
1. Coprime
“In number theory, two integers and are said to be relatively prime, mutually prime, or coprime (also spelt co-prime) if the only positive integer that divides both of them is 1. That is, the only common positive factor of the two numbers is 1. This is equivalent to their greatest common divisor being 1”
https://en.wikipedia.org/wiki/Coprime_integers
For example: and as they only are mutually divided by
2. Modulo
“Given two positive numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is the remainder of the Euclidean [(this means a division that results in a quotient and a remainder when two integers are divided)] division of a by n. For example, the expression “” would evaluate to because divided by leaves a quotient of and a remainder of 1, while “” would evaluate to 0 because the division of by has a quotient of and leaves a remainder of ; there is nothing to subtract from after multiplying 3 times .”
https://en.wikipedia.org/wiki/Modulo_operation
3.Asymmetric Encryption
“Asymmetric Encryption is a form of Encryption where keys come in pairs. What one key encrypts, only the other can decrypt.
Frequently (but not necessarily), the keys are interchangeable, in the sense that if key A encrypts a message, then B can decrypt it, and if key B encrypts a message, then key A can decrypt it. While common, this property is not essential to asymmetric encryption.
Asymmetric Encryption is also known as Public Key Cryptography, since users typically create a matching key pair, and make one public while keeping the other secret.”
http://hitachi-id.com/resource/itsec-concepts/asymmetric_encryption.html
4.Distinct Primes
“A pair of distinct prime numbers are primes p,q such that p≠q .”
https://math.stackexchange.com/questions/1803065/what-is-a-distinct-prime
Formula collection
– Euler’s Totient function
¬ Counts up all the relatively prime numbers to N
¬ and are two prime numbers
Introduction
In the 1970 paper “A Method for Obtaining Digital Signatures and Public-Key Cryptosystems” the three scientists R.L. Rivest, A. Shamir, and L. Adleman proposed a solution of how to secure and to sign electronic mails to maintain privacy and certainty of the sender of letters. The RSA code, shorthand for the three last names of the mathematicians, is the encryption based on encryption key distribution which involves a public and a private key per person. It is the most widely used encryption used on the web and has created a market for extremely large prime numbers, which are, when found, often rewarded with multi-thousands of pounds as they are so essential to providing the necessary security for the data exchange on the internet. The beauty of the RSA code from today’s viewpoint is not only the revolutionary security of the code but that it has democratised encryption on a large scale, as individuals are now able to secure their letters with the same security as the most advanced national intelligence services. One of its current uses is to enable news reporters to report in a secure manner from countries that suppress fundamental right like the freedom of speech. On the other hand, RSA is again a story of how cryptography demands its true heroes to make a sacrifice for their country. Similar to Alan Turing the great mind behind cracking the Enigma code, “Clifford Christopher Cocks CB FRS (born 28 December 1950) is a British mathematician and cryptographer. In 1973 he invented a public key cryptography algorithm equivalent to what would become (in 1978) the RSA algorithm while working at the United Kingdom Government Communications Headquarters (GCHQ). The idea was classified information and his insight remained hidden for 24 years, despite being independently invented by Rivest, Shamir, and Adleman in 1977.” (1.)
Personally, I became engaged with the topic cryptography when a good friend of mine recommended me the book “The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography” after I had watched a documentary about Alan Turing breaking the Enigma machine, which to my disappointment only scratched the surface of the maths behind the topic. The book covers the history of cryptography in rough terms, but the chapter about the present, which was a short introduction to the RSA code and its universal importance offered me the opportunity to take a closer look at the topic for my mathematics exploration. My goal is to gain insight into the world of “Peer to Peer” encryption, from individual to another individual, and to keep record of this with a special focus on its mathematical principles.
RSA Decryption and Encryption
Theory
1. Represent Message as a numerical value
An encryption with the RSA method involves a public key (e,n), both positive integers, to encrypt a message A. We will describe how this key is created later.
The message A should be a numerical number and follow the property, . Cypher text A can also be broken into multiple parts before representing them in numbers.
2. Encrypting the number
The number is then encrypted by raising the number by the power of e and then taking the modulus n of the result. The deciphered text is then the remainder.
3. Decrypting the deciphered text
To decrypt the message the deciphered number is raised by the power of d and then the modulo n is taken
Key generation
1. Theory
As encryption key (e,n) and decryption key (d, n) are positive integers they are both generated by the receiver of the message. By publicising the encryption code other users can encrypt the message A before sending it through an unsecured channel. Only the receiver now has the corresponding decryption key to find A from the deciphered text C.
2. Creating corresponding encryption and decryption key
Both keys contain n so it will be a public value. It is the product of two distinct primes p and q. This means p and q are hidden as long as p and q are extremely big prime numbers as it is difficult to factorise p and q from the n value.
The e value is a random coprime integer to the value derived from this equation
and it has to follow certain properties, it has to be coprime with
and with ,
which are the amount of numbers which are coprime with n. Furthermore, it should be higher than 1 and .
As p and q are unknown by other parties then the generator of the e variable is also unknown to other parties. Value d is a multiplicative inverse of e and is calculated in the following way
Translated this means d is any integer that when multiplied by e has
that is equal to 1.
To strengthen the cypher, it is of great importance to choose enormously high values for d. This is true, because the method of finding the second pair in an asymmetric encryption involves factorising the primes when the size of the primes increase which takes a computer longer to do. At about the length of 2048 bits which are 617 decimal digits it is not possible for our current technology to factorise these numbers as it is nearly 3 times bigger than the biggest ever factorised RSA key; if this should be accomplished a 200 000-dollar prize is offered.
Following this method through, values for n, e and d are computed from the two prime numbers p and q. You can look at the published encryption code (e, n) as a lock that everyone can take to lock a box with the message inside and only you have the keys (d, n) to open-up the box with the message to read it.
Real world Example (4.)
Explaining the theory about RSA with a simple real world example (simple as we will use small prime numbers to present the theory without over complicating the key generation). Given we have two Persons. Person A and person B who would like to exchange the following code word “Like Life” securely without any person or institution C able to intercept the message.
“Like Life!”
Firstly, we must translate the text in a sequence of numbers to modify it. To simplify the translation, we reduce the text by its space between words and its punctuation. We can use an alphabet based translation like in Figure 1, these two steps would alter the text in the following way.
“likelife”
12-9-11-5-12-9-6-5
Secondly, Person B who is receiving the message must generate its set of keys.
Generating keys: Public key (e,N) Private Key (d,N)
Those two keys will represent two number pairs that will allow the encryption of a message (value) with the number e and for decryption of the new calculated value the number d and only d.
Step 1
• Picking two prime numbers and
• Multiply these two numbers
• Find the coprime numbers to N=14
1. write out all the numbers of one to 22
1-2-3-4-5-6-7-8-9-10-11-12-13-14
delete all numbers that have a common factor with 22
(as 2 and 11 are prime numbers these are the only factors of 22)
1-2-3-4-5-6-7-8-9-10-11-12-13-14
left are the numbers 1-3-5-7-9-13
2. counting them up
• Choose
1. because of the limited range eliminate 1 and
1-2-3-4-5
because it must be coprime with and eliminate
2-3-4-5-
We are left with 3 numbers which satisfy the conditions for e
2. In this case, we use e=5
• Choose
1.
d1= 5,11, …
2. For reasons that go into much detail of code deciphering, it is advised not to choose the first few multiples of n when choosing d, as it increases the chance for the cipher to be cracked. In this example, to allow us to follow the maths, we use d2= 11
• Person B ends up with the Public key (5,14) which then can be distributed among all the persons that would like to send “B” an encrypted message that only B can encrypt with the Private key. This private key (11,14) is then the only way to decrypt the message.
Assuming Person A received the Public key how would it now encrypt the number?
The following is the example of encrypting 2 (=B) with the key (11,14)
So, when intercepted, assuming the intercepting party does also know the translation table (figure 3), 4 would equal the letter D.
On the other hand, Person B can now decipher the number 4 with the private key (11,14)
When the encryption key (5,14) is applied to the longer quote the translated numbers would change into the following sequence which could then be sent or published and could be intercepted by any party without exposing the real message.
When the deciphering private key is applied to person B the real sequence would be restored and could be translated back into the quote with the (figure 3) translation table.
Note on the Example: To encrypt letters above the value of 14 the public key has to be bigger than the highest number that is encrypted otherwise two numbers have the same number when encrypted. The same applies to 1. In this example the letter A, the encryption, will in any case be 1 again which doesn´t fit the purpose of deciphering the message. This problem can be solved by shifting the Translation table by 1. This means A first equals 1, after shifting it equals 2, equally for B which afterwards equals 3.
Why does it work (7.)
Inverse relationship of the Keys
The key exponent components e and d must be inverses to each other in respect to . This is defined by the calculation that both and are equal to 1
This is the reason why and
Fermat’s Little Theorem
“Fermat’s Little Theorem states that if p is a prime number, then for any integer a, the number ap − a is an integer multiple of p.”(8.)
This is also shows that Fermat´s Little Theorem is a special case of Euler’s Theorem
∀a∈ZN
as stands in this case for Euler’s totient function described in the Formula collection
Proof (5.)
The aim is to prove the following:
♣ The greatest common denominator of p and q is 1
♣ N is the product of p and q ( N=pq)
♣ Taking mod of the product of e and d is equal to 1
Combined this gives the formula
(me)d=m modN ∀m∈ZN
Explained
• ∀is the symbol for all (6.)
• m∈ZN m is a positive integer {0,1,2,3,4,…}
• m can only be recovered when raised by e and then raised by the power d and then the mod of the product of the two primes p and q is calculated.
This is derived from
∀m∈ZN
Eulers Theorem
is true for all integers we need to consider the following.
First of all, as and they were derived so that .
This inverse relation states that the following is true:
and .
Furthermore as, and are distinct primes that means they are different and their greatest common denominator is 1 ().
Keeping the inverse relation in mind we can prove that
Med ≡ M mod n with the Chinese Remainder Theorem.
In the case of mod p then must be . But in the case that
, then
This explains that we can modify term Med in the following
This shows Med ≡ M mod p is true for all integers M.
Replacing p by q in the previous argument shows that
for all integers M.
Conclusion
Reflecting on the RSA crypto system, I was astonished when doing my research, to find out about the extent and the relevance of the RSA method. It helped me a lot to understand the fine details of modern cryptography which I find particularly relevant as internet traffic is now saved by the authorities in Britain. In addition, the headlines of the newspaper inform about the general interception of email by the NSA. Also, the industry has benefited hugely from online banking as hackers now have a hard time trying to crack the transmitted details. On the other hand, this cryptosystem can only work because of the ever increasing computational capabilities of modern computers which makes the code extremely useful in combination with a computer, but impractical outside of these boundaries.
If I had more time to look into cryptosystems I would like to look in depth into the history of cryptography. In particularly I am interested in the enigma machine used in the second world war as they marked the first steps of the modern computer and their use in cryptography.
Appendix
Proof for modulus
Quotient Remainder Theorem2
Proof:
When any integer A, and a positive integer B, there exist unique integers Q and R such that: where
Therefore, we firstly want to proof that R and Q exist and that they are unique.
To proof that Q and R do exist we have to suppose A is integer and B a positive integer. So when A is divided by B there will be a integer and a decimal (or fraction) left.
When as w and f positive:
if
the integer is labeled as the whole part that we also can say
multiplying this by B
is therefore in other terms
Showing
Therefore to prove R is an integer
or
and as are all integers a integer minus two integers multiplied will always give an integer which means is also an integer.
As we evaluated and B is a positive integer, then the integers and will give this equation: if
when is negative it means
if
if w as and as and this shows R does statisfy
therefore, an integer
For
For adding
when multiplied by B this givesand in other terms can be labled as
To show that it does satisfy
To prove that R is an integer this means:
or
rearranging it
are integers so must be
so when we have worked out that B, a positive integer, there exist integers and such that: where
Sources
1. https://en.wikipedia.org/wiki/Clifford_Cocks ; 18.05.17
2. https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/the-quotient-remainder-theorem ; 12.09.17
3. http://atmosinfo.com/letters-and-numbers-code.html ;15.05.17
4. Inspired by https://www.youtube.com/watch?v=oOcTVTpUsPQ; 24.05.17
5. https://crypto.stackexchange.com/questions/2884/rsa-proof-of-correctness ;18.05.17
6. https://en.wikipedia.org/wiki/List_of_mathematical_symbols ;15.05.17
7. http://doctrina.org/Why-RSA-Works-Three-Fundamental-Questions-Answered.html; 23.05.17
8. http://faculty.cs.tamu.edu/klappi/alg/rsa.pdf ; 25.05.17
Bibliography
“A Method for Obtaining Digital Signatures and Public-Key Cryptosystems” by Rivest, Shamir, Adleman
“The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography” by Simon Sighn