Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1 Definitions
Definition 1. Trapdoor/one-way function
Function f satisfying:
1. f (m) can be computed quickly
s ≡ c−1 mod m
ad ≡ 1 mod m
notation
ordm (a) = d
Definition 6. Co-prime numbers
We say n, m ∈ Z are coprimes iff gcd(n, m) = 1
1
Definition 7. Primitive root modulo n
A number g is primitive root modulo n if every number a coprime to n is
congruent to a power of g modulo n.
In other words g generates multiplicative group modulo n. This is the case iff
Definition
Qn 9. Liouville λ function
Let n = i=0 pαi
i
then
n
Y Pn
αi αi
λ(n) := (−1) = (−1) i=0
i=0
i=0
n
Y αi +βi
= (−1)
i=0
Yn n
Y
αi βi
= (−1) + (−1) = λ(n)λ(m)
i=0 i=0
is multiplicative:
Proof. Let gcd(m, n) = 1. Suppose both are square free. Then it follows from
the fact about λ function. Suppose one of them is not, without loss of generality
assume its m, then µ(mn) = 0 = µ(m)µ(n). To see that its not completely
multiplicative consider µ(p)µ(p) where p is prime.
2
Definition 11. Number of positive divisors τ (n)
We define τ (n) as number of positive divisors of n. That is
τ (n) = card{d ∈ Z+ : d | n}
τ (p) = 2
and
τ (pk ) = k + 1
σ(p) = p + 1
2n = σ(n)
example: 6 = 1 + 2 + 3
Definition 14. Open key cryptosystem
Algorithm with public and private keys
g(n) ∈ O (f (n))
if
∃ N : ∀ n ≥ N : g(n) ≤ Cf (n)
Definition 16. Polynomial time
Algorithm is said to be polynomial time if number of bit operations required to
perform it is a in O class with some polynomial.
3
2 Algorithms
Algorithm 1. Fermat factorization
TODO
Algorithm 2. Successive squaring
Method to find an mod m
2i
P
1. We write n as sum of power of twos n = i
r
2. We compute the sequence cr := 22 mod m
3. We compute:
2i i
P Y
an ≡ a i ≡ a2 mod m
i
Example:
2360 mod 1739
First step:
360 = 28 + 26 + 25 + 23
Second step
0
22 ≡ 2 mod 1739
1
22 ≡ 4 mod 1739
22
2 ≡ 16 mod 1739
3
22 ≡ 256 mod 1739
24
2 ≡ 1193 mod 1739
5
22 ≡ 747 mod 1739
26
2 ≡ 1529 mod 1739
7
22 ≡ 625 mod 1739
28
2 ≡ 1089 mod 1739
Third step:
8 6 5 3
2360 ≡ 22 × 22 × 22 × 22 ≡ 1089 × 1529 × 747 × 256 ≡ 667 mod 1739
4
Algorithm 3. Compute kth root modulo Suppose
xk ≡ a mod m
3. Find x ≡ as mod m
See that
a ≡ ask+tφ(m)
≡ ask atφ(m)
Since aφ(m) ≡ 1
≡ ask
Example:
Lets find x101 ≡ 262 mod 667:
We start by noting that:
φ(667) = 22 ∗ 28 = 616
We have
x ≡ 26261
We use successive squaring
61 = 25 + 24 + 23 + 22 + 20
Now:
0 2 4
2622 ≡ 262 2622 ≡ 581 2622 ≡ 146
1 3 5
2622 ≡ 610 2622 ≡ 59 2622 ≡ 639
We have
5 4 3 2 0
26261 ≡ 2622 × 2622 × 2622 × 2622 × 2622
≡ 262 × 581 × 59 × 146 × 639
≡ 223
5
Algorithm 4. RSA
Let Bob be the user!
1. First, bot chooses two big prime number p, q and computed
n = pq
and
phi(n) = (p − 1)(q − 1)
Finally Bob chooses encryption exponent e such that gcd(e, φ(n)) = 1.
Bob computes the decryption expontent
φ(n) = (p − 1)(q − 1) = pq − p − q + 1
p + q = n − φ(n) + 1
We found a sum of p, q.
Consider a polynomial
g(x) = x2 − (p + q)x + n
Now
g(p) = p2 − p2 − pq + pq = 0
g(q) = q 2 − pq − q 2 + pq = 0
6
1. Choose a such that 1 < a < n
2. If gcd(a, n) 6= 1 then n is composite
3. Otherwise compute
an−1 mod n
if the result is not 1 its composite.
4. Repeat a few times.
Definition 17. Pseudoprime
If a, n are numbers such that
an−1 ≡ 1 mod n
and n is composite, we call n pseudo-prime for the base a.
Definition 18. Carmichael number
A composite number n is called Carmichael number if
an−1 ≡ 1 mod n
is satisfied for any a comprime with n.
3 Theorems
Theorem 1. Congruence’s form equivalence classes
1. a ≡ a
2. If a ≡ b mod m then b ≡ a
3. If a ≡ b and b ≡ c then a ≡ c
Theorem 2. Basic properties of modular arithmetic
Let a ≡ a0 mod m and b ≡ b0 mod m then
1. a + b ≡ a0 + b
2. ab ≡ a0 b0
Theorem 3. Modular cancellation
Let gcd(c, m) = 1 then ac ≡ bc mod m implies a ≡ b
Proof. We have
1 = sc + tm
it follows
sc ≡ 1 mod m
Multiplying both sides of ac ≡ bc we get
asc ≡ bsc
a≡b
7
Theorem 4. Divisibility and sum of digits
n is divisible by
1. 9 if its sum of digits is divisible by 9
2. 11 if alternative sum of its digits is
See that
10 ≡ 1 mod 9 =⇒ 10n ≡ 1 mod 9
then
n
X
a≡ di mod 9
i=0
1, p, 2p, 3p . . . pd−1 p
ϕ(pd ) = pd − pd−1
8
Theorem 6. Properties of euler totient function (cont)
Suppose
Yk
n= pα
i
i
i=0
Then
1 1
ϕ(n) = (pα0 − pα0 −1 )(pα1 pα1 −1 ) . . . (pαk pαk −1 ) = n 1 − ... 1 −
p0 pk
Proof. We have
k
!
Y
ϕ(n) = ϕ pα
i
i
i=0
k
Y
= ϕ(pα
i )
i
i=0
k
Y
αi −1
= pα
i − pi
i
i=0
k
Y 1
= pα
i 1−
i
i=0
pi
k
! k
!
Y Y 1
= pα
i
i
1−
i=0 i=0
pi
k
Y 1
=n 1−
i=0
pi
9
To do this we will construct bijection between this sets.
Consider some (y, z) in sets of residues of m, n. Then by Chinese remainder
theorem there exists residua of mn: x such that
x≡y mod n
x≡z mod m
x ≡ a1 mod m1
...
x ≡ ar mod mr
Qr
then we can construct unique solution to this system modulo M = i=1 mi .
This method can sometimes be useful for finding big exponents. Suppose we
want to find
2360 mod 1739
We can then
x ≡ 2360 mod 37
360
x≡2 mod 47
Proof. Let
M
∀ 0 < k ≤ r : Mk :=
mk
similarly. For all k, let yk be such number that
M k yk ≡ 1 mod m1
Let
r
X
x := ai Mi yi
i=1
10
We claim that x is a number we all looking for. To prove it: let consider
r
X
x≡ ai Mi yi mod mc
i=1
≡ ac Mc yc mod mc
≡ ac mod mc
aR := {ar : r ∈ R}
ar ≡ ar0 =⇒ r ≡ r0 =⇒ r = r0
Since all ar are distinct representatives from each invertible congruent class ar
is reduced system.
Theorem 11. Euler-Fermat theorem
Let gcd(a, m) = 1 then
aϕ(m) ≡ 1 mod m
Proof. Consider reduced system of residues
R := {r0 , r1 . . . , rϕ(m) }
Then, from previous proposition aR generates the same set but in “different
order”. That gives as
Note that first step is valid because each ri ≡ 1 mod m
1 ≡ r0 r1 r2 . . . rϕ(m)
≡ ar0 × ar1 × ar2 . . . arϕ(m)
≡ aϕ(m) r0 r1 r2 . . . rϕ(m)
≡ aϕ(m)
ap−1 ≡ 1 mod p
where p is prime and a 6= p.
Theorem 12. ord and ϕ
Let gcd(a, m) = 1 then
ordm (a) | ϕ(m)
11
Proof. From Euler-Fermat aϕ(m) ≡ 1 mod m. Consider ϕ(m) = qordm (a) + r
then:
aϕ(m) ≡ aqordm (a) ar ≡ ar ≡ 1 mod m
Since r can’t be positive integer smaller then d it must be zero.
Theorem 13. Little Fermat Euler 2
Let p be prime
ap ≡ a mod p
Proof. If gcd(a, p) = 1 then its immediate consequence of Little 1. Else
a ≡ 0 ≡ ap mod m
aϕ(pq)+1 ≡ a mod pq
Proof.
Theorem 16. Sum of divisors and multiplicative function
Let f be multiplicative. Then the function
X
F (n) := f (d)
d | n
is also multiplicative.
Proof. Let gcd(m, n) = 1 First lets proof that there is a bijection
{d | n} × d | m
and
{d | nm}
See that (a, b) 7→ ab, because m, n are relatively prime Now:
X
F (nm) = f (d)
d | nm
12
Here we can push independent term before second sum
X X
= f (d) f (d)
d | n d | m
= F (n)F (m)
n = 2k 2k+1 − 1
2k+1 − 1 | 2n = 2k+1 m
m = (2k+1 − 1)l
contradiction. Now lets suppose we have a number of the form given above,
then
σ(2k (2k+1 − 1)) = σ(2k+1 − 1)σ(2k ) = 2k+1 (2k+1 − 1)
13
Theorem 19. Sum of divisor over euler phi
We want to show: X
φ(d) = n
d | n
X k
X
φ(d) = φ(pk )
d | pk i=0
k
X
=1+ pi − pi−1
i=1
= 1 + pk − 1
= pk
Now let Y
n= pα
i
i
then (we use the fact the φ is multiplicative and that sum over divisors also is)
X Y X
φ(d) = d
i α
d | n d | pi i
Y
= pα
i
i
i
=n
{a ∈ Z : 0 ≤ a < n ∧ gcd(a, n) = d}
is equal to φ( nd )
14
Proof. Lets consider this given set.
If we divide every element of this set by d we get a reduced residua system of
some number. Lets describe this set:
na o
∈ Z : 0 ≤ a < n ∧ gcd(a, n) = d
d
n
We see that all elements in this set are less then d. Lets consider b in this set
and n
gcd b,
d
If d | b then d2 | bd. Now if d | nd we get contradiction because in original set we
would have gcd equal to d2 . And if d 6 | nd gcd must be 1. Similarly, if d 6 | b gcd
must be one. Therefore this set is clearly a subset of reduced residua classes.
Now suppose that x is element of reduced residua class of nd . Then
n
1 = sx + t
d
multiplying both sides by d
d = (sd)x + tn
That is, it must be part of original set.
Theorem 22. Sum of divisors of n under µ
We will show X n
µ(d) = 1 if n = 10 if n > 1
d | n
15
Proof. Lets get to it:
X n X X
µ(d)F = µ(d) f (e)
d n
d | n d | n e | d
X X
= µ(d)f (e)
n
d | ne | d
n n
There exist bijection from (d, e) with d | n and e | d to e | n and d | e
X X
= µ(d)f (e)
n
e | nd | e
X X
= f (e) µ(d)
n
e | n d | e
From previous theorem we can see that only case when second sum is non zero
is when ne = 1, that is n = e
=n
and X n
n= σ(n)µ
d
d | n
16
Algorithm 6. Complexity of operations:
Addition: O (n)
Subtraction: O (n)
Long multiplication: O n2
Karatsuba: O nlog2 3
Computing gcd: O n3
Successive squaring: O n3
√ k
Checking primality (naive): O 2
• Its transitive!
Theorem 25. Relation of Big O with limits
If
f (k)
lim =L<∞
k→∞ g(k)
We consider
g(x) ≡ 0 mod m
And here are two assertions
17
1. We can replace ai with another coefficient
a0i ≡ ai mod m
4 Tutorials
4.1 Tut1
Exercise 2. Use Fermat’s factorization method to factorize 629 and 3139.
Exercise 3. Let k be a positive integer and p a prime. Find a formula for the
sum of all the (positive integer) divisors of pk .
Proof. Simply:
k
X
pi
i=0
18
Exercise 4. Show that for any a, b ∈ Z+ we have
gcd(2a − 1, 2b − 1) = 2gcd(a,b) − 1
2b − 1 | 2a − 2r
After re-writing
2b − 1 | 2r (2qb − 1)
which follows from first assertion.
Now we notice the analogy of to Euclidean algorithm and we are done.
Exercise 5. Determine all pairs of positive integers n, m such that p = n4 +4m4
is prime.
4.2 Tut 2
Exercise 6. Show that l2 ≡ k 2 mod p =⇒ l ≡ ±k mod p if p is prime.
Proof. Consider
(l2 − k 2 ) ≡ 0 mod p
that means
p | (l − k)(l + k)
which can only be a case if l = ±k
Exercise 7. Suppose p is prime and q is prime such that q is a divisor of 2p − 1.
Show that
q ≡ 1 mod p
19
Proof. Its given that
2p − 1 ≡ 0 mod q
which we will rewrite as
2p ≡ 1 mod q
We notice that this means ordq (2) | p. But since
ordq (2) > 1
we have
ordq (2) = p
From Fermat Little theorem
2q−1 ≡ 1 mod q
Since only multiple of ord can give 1 we now that
ordq (2) | q − 1
which is equivalent to stating
p | q−1
But then
q≡1 mod p
4.3 Tut 3
Exercise 8.
5 Quiz
5.1 Sample quiz 1
Exercise 9. Find gcd(1020 , 84).
We start by observing:
1020 = 220 × 520
84 = 22 × 3 × 7
Clearly greatest common divisor is 22 = 4.
Exercise 10. Find the smallest prime that divides 123456789123456789.
Clearly its not 2 since 2 6 | 9. We recall that number is divisible by 3 iff sum of
its digits is divisible by 3 and now we can check:
1+2+3+4+5+6+7+8+9+1+2+3+4+5+6+7+8+9 = 2×(1+2+3+4+5+6+7+8+9) = 3+3+9+6+15+9
Notice that all terms in a last sum are divisible by 3 therefore sum also is, and
number as well.
20
Exercise 11. Find which elements 1 ≤ x < 59 is inverse to 17 modulo 59
TODO
Exercise 12. Find the order of 5 modulo 31.
5≡5
52 ≡ 25
53 ≡ 1
So ord31 (5) = 3
Exercise 13. Find the residua of 31010 modulo 7
We see that 1010 = 2 × 505
3≡3
32 ≡ 2
34 ≡ 4
35 ≡ 5
36 ≡ 1
x≡3 mod 14
x≡2 mod 15
TODO
Exercise 15. Find 21010 mod 111.
We see that 2φ(111) ≡ 2ϕ(3)ϕ(37) ≡ 272 ≡ 1
Exercise 16. Find σ(640), sum of the positive divisors of 640.
See that 640 = 64 × 10 = 27 × 5
Therefore
28 − 1
σ(640) = σ(27 )σ(5) = (5 + 1) = 6(28 − 1)
2−1
Exercise 17. What is the smallest positive integer with exactly 10 positive
divisors.
TODO
Exercise 18. If a simple substitution cipher encrypts the word SUGAR as
JWZXD, what is the decryption of XDZWJ?
TODO
21
Exercise 19. What would be the output of the following MAGMA commands?
> V:=VigenereCryptosystem(3);
> encipheringkey:=V!”BAY”;
> Enciphering(encipheringkey,Encoding(V,”HOTEL”));
TODO
Exercise 20. Suppose you are given two long ciphertexts sct1 and sct2 and
told that one of them is some ordinary English text enciphered with a block
transposition cipher and the other is the same English text enciphered with a
Vigenere cipher. If you see the following MAGMA code, which one was (prob-
ably) enciphered using the block transposition cipher?
> CoincidenceIndex(sct1);
0.0652012312147048057406882815071
> CoincidenceIndex(sct2);
0.0415879787948780874621427836594
The sct1.
Exercise 21. If an RSA cryptosystem has public key (22, 3), what is the
decryption exponent?
TODO
Exercise 22. Suppose that an RSA cryptosystem has a public key of (33, 3).
Encrypt the message [4, 6].
TODO
Exercise 23. What would be the output of the following MAGMA commands?
> p:=NextPrime(100);
> 6p mod p;
From Fermat Little Theorem it follows that output would be 6.
22