Intro To Cryptography - Chapter 2
Problem 2.3
Let g be a primitive root for Fp.
(a) Suppose that x=a and x=b are both integer solutions to the congruence gx≡hmodp. Prove that a≡bmodp−1. Explain why this means that the map (2.1) on page 65 is well-defined.
Proof: Let a−b=(p−1)⋅q+r such that 0≤r<p−1. If we can show that r=0, then by definition we can conclude a≡bmodp−1. Notice that
h≡ga=gb+(p−1)⋅q+r=gb⋅(gp−1)q⋅gr≡h⋅grmodp.
To be pedantic, we know h has an inverse hp−2, so we can multiply both sides of this equivalence by the inverse to find that 1≡grmodp. But recall 0≤r<p−1; because g is a generator, it must be the case that r=0, completing the proof.
Lastly, by definition logg is a well-defined function if it maps deterministically; that is, h=j⟹logg(h)=logg(j) for all h,j∈Fp∗. Recall that g is a generator, so we can write h=ga and j=gb for some a,b∈Z. Equivalently, ga=gb in Fq∗. From the statement proved above, we know that this implies a=b in Z/(p−1)Z. Therefore logg(h)=logg(j) and logg is well-defined.
(b) Prove that logg(h1h2)=logg(h1)+logg(h2) for all h1,h2∈Fp∗.
Proof: Let a,b∈Z/(p−1)Z such that ga=h1 and gb=h2. Then
logg(h1h2)=logg(gagb)=logg(ga+b)=a+b=logg(h1)+logg(h2).
(c) Prove that logg(hn)=nlogg(h) for all h∈Fp∗ and all n∈Z.
Proof: First we'll handle n≥0 by induction. For the base case, clearly
logg(h0)=logg(1)=0=0⋅logg(h).
Next suppose for some k>=0, logg(hk)=klogg(h). By part (b) we have
logg(hk+1)=logg(hkh)=logg(hk)+logg(h)
and by the inductive hypothesis,
logg(hk+1)=klogg(h)+logg(h)=(k+1)logg(h).
We conclude by induction that the statement holds for all n≥0. For negative numbers, let's do induction in reverse. First, let's consider the base case of a negative exponent:
h−1=h−1⋅1=h−1⋅hp−1=hp−2
in Fp∗, a fact which we've previously seen in the fast powering algorithm. Since we've already proved this for nonnegative integers, and p−2≥0, we have
logg(h−1)=logg(hp−2)=(p−2)logg(h)=(p−1)logg(h)−logg(h)=−1⋅logg(h).
Suppose our statement holds for some k≤−1. Then
logg(hk−1)=logg(hkh−1)=logg(hk)+logg(h−1)
and by the inductive hypothesis and base case, we know
logg(hk)+logg(h−1)=klogg(h)−logg(h)=(k−1)logg(h).
By induction, we conclude the statement holds for all negative integers n. We have thus tediously and pedantically completed the proof.
Problem 2.6
Alice and Bob agree to use the prime p=1373 and the base g=2 for a Diffie-Hellman key exchange. Alice sends Bob the value A=974. Bob asks your assistance, so you tell him to use the secret exponent b=871. What value B should Bob send to Alice, and what is their secret shared value? Can you figure out Alice's secret exponent?
Solution: Bob should send
B=gbmodp=2871mod1373=805
Their secret shared value is
S=Abmodp=974871mod1373=397.
Since there are at most 1372 values to search for p=1373, it is quite easy to find a=587:
const A: u32 = 974;
const P: u32 = 1373;
let e = (1..P).find(|&e| mod_pow(2, e, P) == A);
assert_eq!(e, Some(587));
Problem 2.9
Suppose that Eve is able to solve the Diffie-Hellman; that is, given gu,gvmodp, then she is able to compute guvmodp. Show that Eve can break the Elgamal PKC.
Proof: Suppose Alice and Bob are communicating via Elgamal with parameters g,p, where Alice has chosen private key a and public key A. Suppose further that Bob has used random element k in his encryption of ciphertext (c1,c2). We need to show that Eve can recover the underlying plaintext m.
Eve can do this by using her Diffie-Hellman oracle with values A=ga and c1=gk to obtain s=gak. Then she can compute the inverse s−1 (via the sp−2 and fast powering algorithm for example) and use it to find m:
c2⋅s−1≡mAk⋅(gak)−1≡m⋅gak⋅(gak)−1≡mmodp
Problem 2.14
Prove that each of the following maps is a group homomorphism.
(a) The map ϕ:Z→Z/NZ that sends a∈Z to amodN.
Proof: Let a=N⋅qa+ra and b=N⋅qb+rb such that 0≤ra,rb<N. It follows that ϕ(a)=ra and ϕ(b)=rb. Finally
ϕ(a+b)=ϕ(N⋅qa+ra+N⋅qb+rb)=N⋅qa+ra+N⋅qb+rbmodN≡ra+rb≡ϕ(a)+ϕ(b)modN
(b) The map ϕ:R∗→GL2(R) defined by
ϕ(a)=(a00a−1).
Proof: Let a,b∈R∗.
ϕ(a)ϕ(b)=(a00a−1)(b00b−1)=(ab00a−1b−1)=(ab00(ab)−1)=ϕ(ab)
(c) The discrete log map logg:Fp∗→Z/(p−1)Z where g is a primitive root modulo p.
Proof: This follows immediately from Problem 2.3(b) proved above.
Problem 2.19
Solve the 1700-year-old Chinese remainder theorem problem from the Sun Tzu Suan Ching:
We have a number of things, but we do not know exactly how many. If we count them by threes, we have two left over. If we count them by fives, we have three left over. If we count them by sevens, we have two left over. How many things are there?
Solution: This translates to the following system of congruences:
- x≡2mod3
- x≡3mod5
- x≡2mod7
We can satisfy the first congruence generally with x=2+3y. Substituting this into the second congruence,
2+3y≡3mod5⟹3y≡1mod5
and, using the program written for 1.34c, we find 3−1≡2mod5, so
y≡2mod5
and this gives the value
x=2+3y=2+3⋅2=8
as a solution to the first two congruences. A general solution is thus
x=8+15z.
Substituting this into the third equation yields
8+15z≡2mod7⟹z≡1.
Finally,
x=8+15z=8+15=23.
A quick sanity check shows that indeed:
- 23≡2mod3
- 23≡3mod5
- 23≡2mod7
Problem 2.35
Let
a=x5+3x4−5x3−3x2+2x+2
b=x5+x4−2x3+4x2+x+5
Use the Euclidean algorithm to compute gcd(a,b) in each of the following rings.
(a) F2[x]
- a=b⋅1+(x3+x2+x+1)
- b=(x3+x2+x+1)⋅(x2+1)+0
Therefore gcd(a,b)=x3+x2+x+1.
(b) F3[x]
- a=b⋅1+(2x4+2x2+x)
- b=(2x4+2x2+x)⋅(2x+2)+(x2+2x+2)
- (2x4+2x2+x)=(x2+2x+2)⋅(2x2+2x)+0
Therefore gcd(a,b)=x2+2x+2.
(c) F5[x]
- a=b⋅1+(2x4+2x3+3x2+x+2)
- b=(2x4+2x3+3x2+x+2)⋅(3x)+(4x3+x2)
- (2x4+2x3+3x2+x+2)=(4x3+x2)⋅(3x+1)+(2x2+x+2)
- (4x3+x2)=(2x2+x+2)⋅(2x+2)+(4x+1)
- (2x2+x+2)=(4x+1)⋅(2x+2)+0
Therefore gcd(a,b)=x+4, the monic version of polynomial 4x+1.
(d) F7[x]
- a=b⋅1+(2x4−3x3+x−3)
- b=(2x4−3x3+x−3)⋅(4x+3)+3x
- 4x+3=3x⋅6+3
- 3x=3⋅x+0
Since 1 is the monic version of polynomial 3, gcd(a+b)=1.