Some Applications of Number Theory To RS
Some Applications of Number Theory To RS
SUBMITTED TO
September 2018
Abstract
This project looked at some aspects of Number Theory and its applications of RSA public
key cryptography. This project used a sample message to demonstrate encryption and
decryption application.
1
Dedication
I dedicate this work to God Almighty, who has been and is still my backbone. My parents,
the source of my joy and strength, and my siblings too.
2
Acknowledgment
My profound gratitude goes to my project supervisor, Dr. M. C. Obi who has been a
father to me. I also wish to appreciate him for his patience, his constructive criticisms and
also for giving me a sound academic guidance to achieve and present this work.
I am also indebted to my Head of Department, Dr. C. A. Nse for his tutelage. I wish
to thank all my Professors – Professor S. C. Inyama, Professor A. M. Ette, Professor E. N.
Erumaka, Dr. R. A. Umana, Dr. (Mrs) E. E. Onugha, Dr. (Mrs) Joy U. Chukwuchekwa,
Mrs. Nneka, Dr. Andrew, Mr. Henry, my understanding and excellent course adviser,
Mr. Araka Nnamdi, Mrs. Chinwe Obi and Mrs. Precious and also all the non-academic
staff of the department.
I wish to specially thank my beloved parents, Mr. and Mrs. J. Chukwu whose
prayers, and love have kept me stronger throughout my sojourn in college. I also thank
my siblings for their prayers. I wish to appreciate the support from my course mates.
They have always been a family to me, ever supporting and loving, God bless you all.
Finally, i’d love to appreciate my roommates, KendricX, Martinez, and Chizzy these
awesome people have always been supporting.
3
Contents
1 Introduction 6
1.1 Background of Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 Statement of Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Aim and Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4 Scope of Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5 Definition of Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5.1 Cryptology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5.2 Cryptography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5.3 Cryptanalysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5.4 Encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.5.5 Decryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.5.6 Assymetric Key Encryption . . . . . . . . . . . . . . . . . . . . . . . 8
1.5.7 Euler’s Totient Function . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.5.8 Fermat’s Little Theorem . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.5.9 Euler’s Theorm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.5.10 Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.5.11 Number Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.5.12 Prime Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2 Literature Review 10
3 Methodology 12
3.1 Divisibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1.1 Divisibility Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.1.2 Corollary: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.1.3 Theorem (Algorithm For Computing The G.C.D Of Two Integers) . 13
3.2 Theorem (Euler’s Totient Function) Φ(n) . . . . . . . . . . . . . . . . . . . . 14
3.2.1 Theorem (Euler’s Theorem 1) . . . . . . . . . . . . . . . . . . . . . . 14
3.2.2 Theorem (Euler’s Theorem 2) . . . . . . . . . . . . . . . . . . . . . . 14
3.2.3 Theorem(Fermat’s Little Theorem 1) . . . . . . . . . . . . . . . . . . 14
3.2.4 Theorem(Fermat’s Little Theorem 2) . . . . . . . . . . . . . . . . . . 14
3.3 Congruence Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3.1 Theorem 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.3.2 Logarithms in Modular Arithmetic . . . . . . . . . . . . . . . . . . . 15
3.4 RSA Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.4.1 Phase 1 (Public and Private Keys Generation) . . . . . . . . . . . . 15
3.4.2 Phase 2 (Encryption) . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.4.3 Phase 2 (Decryption) . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5 RSA Set-Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5.1 RSA: How To Encrypt and Decrypt . . . . . . . . . . . . . . . . . . 16
4
4 Analysis and Results 18
4.1 Application 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.2 Application 2 (Communication Between A Browser And A Server . . . . . 19
5
Chapter 1
Introduction
Encryption plays a crucial role in the day-to-day functioning of our society. For example,
millions of people make purchases on the internet every day. Each time you submit your
credit-card details online, there is a risk that this information may be stolen. So how can
the information be sent securely?
A shopper’s credit-card details need to be encrypted before they are transmitted over
the internet, and so the method of encryption needs to be made public. But the method
of decryption should be known only to the bank that is processing the payment. For all
of the ciphers in use before RSA, the methods of encryption and decryption were known
to both the sender and the receiver of the message. With RSA, the instructions for how to
encrypt a message can be made public, without compromising the security of the method
of decryption. This was the big breakthrough that came with RSA encryption.
• That factorization is intractable or is intractable in the special case needed for RSA,
and
• That factorization is needed for the cryptanalysis of the RSA.
6
this project includes:
1.5.1 Cryptology
This is the term referring to the broad study of secret writing.
1.5.2 Cryptography
This is the development and creation of the mathematical algorithms used to encrypt and
decrypt messages.
1.5.3 Cryptanalysis
This is the science of analyzing and breaking encryption schemes. The purpose of crypt-
analysis is to break the cryptosystem, in other words, to find the decrypting key or
encrypting key, or to at least produce a method which will let us get some information
out of encrypted messages. In this case it is usually assumed that the cryptanalyzer is an
eaves-dropper or some other hostile party and that the cryptanalyzer knows which cryp-
tosystem is being used but does not know the key being used. A cryptanalyzer may have
different information available: (CO) just some, maybe random, cryptotext (cryptotext
only), (KP) some, maybe random, plaintext and the corresponding cryptotext (known
plaintext), (CP) a chosen plaintext and the corresponding cryptotext (chosen plaintext),
(CC) a chosen cryptotext and the corresponding plaintext (chosen cryptotext).
1.5.4 Encryption
This is one specific element of cryptography in which one hides data or information by
transforming it into an undecipherable code. Encryption is used in everyday modern
life. Encryption is mostly used amongst transactions over insecure channels of commu-
nication, such as the Internet. Encryption is also used to protect data being transferred
between devices such as automatic teller machines (ATM’s ), mobile telephones, and
many more.
7
1.5.5 Decryption
This is often classified along with encryptions as it’s opposite. Decryption of encrypted
data results in the original data.
Asymmetric key encryption uses prime extensively. Positive integers can be divided
into three groups: the number 1, prime and composites. A positive integer is a prime if
and only if it is exactly divisible by two integers, 1 and itself. A composite is a positive
integer with more than two divisors. The smallest prime is 2, which is divisible by 2
(itself) and 1. Integer 1 is not a prime according to the definition, because a prime must
be divisible by two different integers, no more, no less. Two positive integers, a and b,
are relatively prime, or co prime, if gcd(a, b) = 1. The integer 1 is relatively prime to any
integer. RSA encryption is based on a special property of the prime numbers. The prime
numbers:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, . . .
are natural numbers greater than 1 which cannot be expressed as a product of smaller
natural numbers. That is, a prime number is a natural number greater than 1 whose only
positive factors are itself and 1. Each natural number greater than 1 can be factorized as a
product of powers of primes. Moreover, if we ignore the order of the prime powers, then
there is only one way to do this. For example, we can write 60 = 22 × 3 × 5. There are
infinitely many prime numbers. Using a computer, it is relatively easy to find lots of large
prime numbers. At present, however, it is very difficult to find the prime factorization of
a very large number. This is what makes RSA encryption so hard to crack.
8
1.5.8 Fermat’s Little Theorem
Fermat’s little theorem plays a very important role in number theory and cryptography.
Two versions of the theorem includes:
• The first version says that if p is prime, α is an integer such that p does not divide α,
then αp−1 ≡ 1modp.
• The second version removes the condition on α . It says that if p does not divide α ,
then , αp–1 ≡ 1mod
Fermat’s little theorem is helpful for quickly finding a solution to exponentiation and
multiplicative inverses. To find 312 mod11, we can use Fermat’s little theorem.
• The first version is similar to that of the first version of Fermat’s little theorem. If α
and n are co-prime, the αφ(n) = 1 mod n
1.5.10 Authentication
Often one of the most important parts of a message is the signature. A person’s signature
let’s the recipient know that the message really is from the person whose name is typed
below. If the the message is particularly important, or the sender wished to make his
signature harder to use, it might be necessary to use additional methods to autheticate
the communication.
Most especially in electronic communication, where one does not have aphysical sig-
natiure, one has to rely on other methods. For example, User A (say John) who stays
in a distant location, and wishes to wire funds through an electronic channel, it is im-
possible to put a signature on the computer, instead he might need to create a password
(a secret key). Hence, when he needs to transfer funds, he simply supplies the secret key
that the banks knows and no other third-party (imposter) would likely know and viola!
money is wired.
9
Chapter 2
Literature Review
There are huge amounts of contributions by researchers in the field of Number Theory
and public key cryptography. Some of these contributions are explained in this chapter.
Ron Rivest, Adi Shamir, and Leonard Adleman (1978) introduced a cryptographic
algorithm, which was essentially to replace the less secure National Bureau of Standards
(NBS) algorithm. Most importantly, RSA implements a public-key cryptosystem, as well
as digital signatures. RSA is motivated by the published works of Diffie and Hellman
from several years before, who described the idea of such an algorithm, but never truly
developed it.
Kefa Rabah (2006) in his paper “Reviewed of methods for integer factorization applied
to cryptography” In this study, hel outlined some useful and recent integer factorization
algorithms, including the Elliptic Curve Algorithm (ECM), Quadratic Sieve (QS), Number
Field Sieve (NFS).
Ying Shi, and Shuang Zhang (2012) in the paper ”A method on safe data transmission
with lossless compression”, they proposed a method on safe data transmission for the
embedded system, which is convenient and of high computational efficiency. This method
not only removes the redundancy by re-encoding, but also encrypts the frame by Rivest
- Shamir - Adleman (RSA) algorithm after scrambling it with a random matrix. The
experimental results show a good security of data transmission and a certain compression
effect. Due to the slow variance in the collected data of embedded system and the existence
of large historical data redundancy, the method mentioned above is more suitable for the
embedded system than the conventional methods.
In the paper “Improved RSA cryptosystem based on the study of number theory and
public key cryptosystem”, Israt Jahan, Mohammad Asif and Liton Jude Rozario (2015)
proposed an improved approach of RSA algorithm using two public key pairs and using
some mathematics logic rather than sending one public key directly.
Juliet N. Gaithuru, Majid Bakhtiari, Alwuhayd M. Muteb and Mazleena Salleh (2015)
provided a description of their encryption and decryption operations, points out their
security basis, areas of implementation, their strengths and weaknesses during operation.
Finally, the paper pinpoints the existing gaps based on the conclusions drawn from the
10
review, with particular emphasis on an algorithm most suited for industrial application
given the current trends in cryptography towards quantum computing. This papers then
narrows down on the earnest need for an algorithm that has no trade-off in encryption
and decryption speeds, has low computation overhead and is secure enough to withstand
quantum algorithm attacks.
Shireen Nisha and Mohammed Farik (2017) in the paper “RSA Public Key Cryptog-
raphy Algorithm” reviewed RSA, examined its strengths and weaknesses, and propose
novel solutions to overcome the weakness. RSA (Rivest, Shamir, and Adleman) is one of
the best cryptographic algorithms in use today that ensures secure communication over
networks.
11
Chapter 3
Methodology
Certain concepts and results of RSA computations existing in the literature review can be
achieved using some mathematical formalism in Number Theory.
3.1 Divisibility
Let b be an integral divisor or factor of b is an integral a such that b = ac for some integer c.
b is also said to be divisible by a or an integral multiple of a. We write a|b if a divides b. If
a|b and 0 < a < b, then a is called ”proper divisor o f b”. For example, a|0 f or all a ∈ Z, a , 0.
|a|b ≥ |a|
and so,
a − (−|a|) b = a + |a| b ≥ a + |a| ≥ 0
Hence, for the choice X = −|a|, a − xb will lie in S. This paves the way for an application
of well ordering principle. It infers that the set S contains a smallest integer, say r. By the
definition of S, there exist an integer q satisfying r = a − qb, 0 ≤ r and with the notion that
r < b. If this were not the case, then r ≥ b and
a − (q + 1) b = (a − qb) − b = r − b ≥ 0
a = bq + r = bq′ + r
12
where 0 ≤ r ≤ b, 0 ≤ r′ ≤ b. Then r′ − r = b(q − q′ ) and for the fact the absolute value of a
product is equivalent to the product of the absolute values,
|r′ − r| = b |q − q′ |.
On adding the two inequalities −b < −r ≤ 0 and 0 ≤ r′ < b, then −b < r < b or equivalently,
|r′ − r| < b, thus b |q − q′ | < 1, Since |q − q′ | is a non-negative integer, the only possibility is
that |q − q′ | = 0. Hence q = q′ . This in turn gives r = r′ . The restriction that b be positive
integer is replaced by b , 0 following corollary is obtained.
3.1.2 Corollary:
If a and b are integers, with b , 0, then there exist unique integers q and r such that
a = qb + r, 0 ≤ r ≤ |b|
proo f : If it is enough to consider the case where b is negative, Then |b| > 0 and the theorem
produces unique integers q′ and r for which
a = q′ |b| + r, 0 ≤ r ≤ |b|
proo f
Now suppose that a, b are two non-zero integers and q, r the unique integers such that
a = bq + r, 0 ≤ r < b
a = bq + r, 0 ≤ r < b
b = rq1 + r1 , 0 ≤ r1 < r
r = r1 q2 + r2 , 0 ≤ r2 < r1
r1 = r2 q3 + r3 , 0 ≤ r3 < r2
..
.
rk−2 = rk−1 qk + rk , 0 ≤ rk < rk−1
rk−1 = rk qk+1 + 0
Since one of the following ri must be zero after a finite number of steps, since ri ’s are
steadily deceasing non-negative integers. Hence (a, b) = (b, r) = (r, r) = . . . = (rk−1 , rk ) = rk
is the g.c.d of a and b.
13
3.2 Theorem (Euler’s Totient Function) Φ(n)
The number of positive integers less than n and relatively prime to n
• Φ(n) = 1
Φ(n) = (Φ(a))(Φ(b))
Φ(n) = (p − 1) ∗ (q − 1)
aΦ(n) ≡ 1(modn)
ap−1 ≡ a mod(p)
ap ≡ a mod(p)
(k + 1)p ≡ k + 1 (modP)
By the principle of induction, it follows that ap ≡ a (modp), for every positive integer a.
14
3.3 Congruence Class
Let n be a positive integer, and let a be an integer. The congruence class of a modulo n
denoted by [a], is the set of all integers that are congruent to a modulo n. That is,
[a] = {b ∈ Z : b ≡ a (modn)}
= {b ∈ Z : b = a + kn, f or some k ∈ Z}
3.3.1 Theorem 1
a ≡ b (mod n) iff [a] = [b].
proo f Assume a ≡ b (mod n). Let c ∈ [a]. Then c ≡ a (mod n). By transitivity, we have
c ≡ b(mod n). Thus c ∈ [b], and so, we have shown that [a] ⊆ [b]. In the same way, it can
be shown that [b] ⊆ [a]. Hence, [a] = [b].
Conversely, assume [a] = [b]. By reflexivity, we have a ≡ a (mod n), and therefore,
a ∈ [a] = [b]. Hence, a ≡ b (mod n)
b = ai
i = loga (b)
In modular arithmetic, it is known as discrete logarithm
b = ai (mod p)
i = dloga,p (b)
A unique exponent i can be found if a is a primitive root of prime p.
• Compute their product n which is the modulus for encryption and decrption.
• Next, we need the quantity, Φ(n) referred to as Euler totient of n. Compute the Euler
totient function Φ(n) = (p − 1)(q − 1).
• Choose a large random number D(D > 1 such that (D; Φ(n)) = 1 (i.e, D and Φ(n) are
relatively prime).
15
3.4.3 Phase 2 (Decryption)
Find the integer D with 1 < D < Φ(n) such that D ∗ E = 1(modn)
CODE
LETTER NUMBER LETTER NUMBER
A 00 N 13
B 01 O 14
C 02 P 15
D 03 Q 16
E 04 R 17
F 05 S 18
G 06 T 19
H 07 U 20
I 08 V 21
J 09 W 22
K 10 X 23
L 11 Y 24
M 12 Z 25
- 26
One would observe that instead of letting A = 0, we equated it to 00. This is because
once we got up to K, we started using double digits. If we have a mix of single digits and
double digits, it would be impossible to convert back to our original message. Also, it
is useful to denote spaces in between words with a number. To this effect, we will use a
”dash” between words instead of space to make it clearer.
p = 3 and q = 11
Step 2 :
Let n = p ∗ q
n = 3 ∗ 11 = 33
Step 3 :
Let Φ(n) = (p − 1)(q − 1)
Φ(n) = 2 ∗ 10 = 20
Step 4 : Choose an integer E with 1 < E < Φ(n) such that gcd(Φ(n), E) = 1. We have several
choices for E but we’ll pick 7 for simplicity
16
Step 5 :
So, the number n = 33, and k = 7 becomes the public key.
Step 6 :
To decrypt , we choose a decryption key D such that
D = E ∗ D mod Φ(n) = 1
= E ∗ D = 1 (mod Φ(n))
7d mod 20 = 1
d=3
17
Chapter 4
4.1 Application 1
The number n and E are the public key; they can be shared with anyone. The number D
is the private keyl it must be kept secret.
Blessing (User A) wants to receive a secret message from John (User B). She sends him
the value of n and E. It doesn’y matter if this message is intercepted by an eavedropper;
the value of n and E can be made public. Only Blessing (User A) must know the value of
D.
Suppose the message John (User B) want to send Blessing is ”HELP”. For simplicity, we
suppose the letters H, E, L, and P were assigned the numbers 2, 3, 4, and 5.
Message = H E L P = 2 3 4 5
To encrypt the message ”HELP”, we apply the encryption formula, Ci = Me mod n, where,
C1 = 27 mod 33 = 29
C2 = 37 mod 33 = 9
C3 = 47 mod 33 = 16
C4 = 57 mod 33 = 14
M = Cd mod n
M1 = 293 mod 33 = 2
M2 = 93 mod 33 = 3
M3 = 163 mod 33 = 4
M4 = 143 mod 33 = 5
18
4.2 Application 2 (Communication Between A Browser And A
Server
A browser wants to send Message = 14 to the server, using the key generation method.
Here is the mathematical formalism the browser executes :
105413504 / 33 = 3194348.606
3194348 ∗ 33 = 10541348
E = 105413504–10541348
E = 20
Encrypted message = 20 will be sent to the server. Here is the decryption algorithm the
server executes to recover the original plain text message which the browser started with
:
Message = Ciphertextd mod n
After plugging in the values
= 14 (Message)
19
Chapter 5
5.1 Summary
Number theory may be one of the “purest” branches of mathematics, but it has turned out
to be one of the most useful when it comes to computer security. This project is a study
application of some aspects of number theory and the RSA public key cryptosystems .
5.2 Conclusion
RSA is a strong encryption algorithm that has stood a partial test of time. RSA implements
a public-key cryptosystem that allows secure communications and “digital signatures”,
and its security rests in part on the difficulty of factoring large numbers. The authors
urged anyone to attempt to break their code, whether by factorization techniques or
otherwise, and nobody till date seems to have succeeded. This has in effect certified RSA,
and will continue to assure its security for as long as it stands the test of time against such
break-ins.
5.3 Recommendation
To improve the findings of this work, I recommend that further research should be carried
out and the topic should be adopted and taught to undergraduates in mathematics as it
would reveal the applications of mathematics and increase there interest in cyber security.
20
Bibliography
21