Number Theory
Relatively prime numbers and greatest common divisor
Naturals Integers Primes
To factor a number is to write it as a product of other numbers, . Multiplying is trivial, but factoring is hard. We cannot factor most numbers with more than 1024 bits.
Prime Factorisation
The prime factorisation of a number amounts to writing it as a product of primes:
Link to original
Divides notation
divides (written ) if there is an such that . e.g.
Link to original
Not divides notation
does not divide (written ) if there is no such that . e.g.
Link to original
Relatively prime numbers
Two natural numbers, and , are relatively prime if they have no common divisors / factors apart from , i.e. if (greatest common divisor).
Link to original
(Extended) Euclid’s algorithm
We can quickly compute using Euclid’s algorithm.
It is based on the theorem that for any non-negative integer and any positive integer .
Euclid's algorithm
The algorithm works as follows:
Link to original
- if then
- return
- else
- return
Example
\begin{aligned} gcd(60, 14)&: 60 &&= (4 \times 14) + \color{red} 4 \
gcd(14, {\color{red} 4})&: 14 &&= (3 \times {\color{red} 4}) + {\color{blue} 4} \ gcd({\color{red} 4}, {\color{blue} 2})&: {\color{red} 4} &&= 2 \times {\color{blue} 2} \end{aligned}
Extended Euclid's algorithm
Extended Euclid’s algorithm also computes (integer coefficients) such that:
The algorithm works as follows:
- if then
- return
- else
- return
Where is the quotient of the division (for ).
Link to original
Example
Using our earlier example, .
Modular arithmetics
Remainder (modular arithmetic notation)
where . Here is the remainder which we write as .
Link to original
Congruent Modulo
are congruent modulo , if . We write this as (i.e. they have the same remainder when divided by some ).
Link to original
Modulo operator properties
The modulo operator has the following properties:
Link to original
- Reflexivity:
- Symmetry: if then
- Transitivity: if and then
- for
- if and is relatively prime to , then .
is relatively prime to so
- if and then
Given with and and :
For any integer , we can rewrite as:
Theorems
Theorem: suppose that are relatively prime. There is a satisfying , i.e. we can compute .
Proof: From Extended Euclid’s Algorithm, there exist where . Since , we have . Assertion follows with .
Fermat's little theorem
Theorem: for and relatively prime and prime:
Proof:
Euler Totient Function
Complete set of residues
When doing arithmetic modulo , complete set of residues is .
Link to original
Reduced set of residues
The reduced set of residues consists of those numbers (residues) that are relatively prime to . For instance, for :
Link to original
- complete set of residues:
- reduced set of residues:
Euler Totient Function
Number of elements in reduced set of residues is called the Euler Totient Function .
Link to original
Properties of Euler Totient Function
Properties of Euler Totient Function:
Link to original
- if is prime
- if and are prime and
So this means Fermat’s little theorem (for and relatively prime and prime) can be rewritten into for all , such that is prime and .
RSA Algorithm
Rivest Shamir Aldeman Block Cipher
The RSA algorithm is a block cipher in which the plaintext and ciphertext are integers between and for some .
- Typically is bits ( decimal digits)
The security of the algorithm comes from the difficulty of factoring large numbers. Keys are functions of pairs of large, digit, prime numbers.
Link to original
Named after inventors Rivest, Shamir, Aldeman
RSA Algorithm
RSA Algorithm
- Let be a number known by sender and receiver.
- Plaintext is encrypted in blocks, with each block having a binary value less than . Block size must be less than or equal to . Each block represents a number such that .
We define RSA encryption and decryption of for some (properly) chosen values of and
It is a public-key encryption algorithm with:
- public key
- private key
For the algorithm to work, the following requirements must be met:
Link to original
- It is possible to find values of , , such that for all .
- It is relatively easy to calculate and for all values of .
- It is infeasible to determine given and .
Correctness of RSA
We must show that there exist such that for all . It can be shown that the equation holds if and are multiplicative inverses , i.e.:
But this is only true if (and ) is relatively prime to , i.e. .
Correctness of RSA (cont.)
Since , there exists such that . Now consider whether or not , i.e. whether .
Case 1: if then by Fermat’s theorem Raising both sides to the power and multiplying by yields
Case 2: if then last congruence is trivially valid since each side is congruent to . Hence in both cases By the same argument and since and are distinct primes, by the Chinese Remainder Theorem it follows that and hence:
Chinese Remainder Theorem
Algorithm Steps
Generation of public / private key pair
- Generate two prime numbers and , these are kept private and are two (large) distinct primes.
- Compute and .
- Select an , with , relatively prime to .
- Compute .
- Public , keep private, discard and .
Encryption with key
- Break message into blocks with
- Compute
Decryption with key
- Compute
Example of RSA Algorithm
Another Example of RSA Algorithm
![]()
![]()
![]()
![]()
![]()
Using RSA to process multiple blocks of data






