258
13 Solutions for Selected Exercises
Exercise 12.6
The following code snippet illustrates the communication between Alice and Bob.
After defining p and g, Bob uses Alice’s public number A and his secret number b
to calculate the encryption key k = A
b
(mod p) that he subsequently uses to decode
the ciphertext c. He finds that the plan is to meet at 17, or 5 pm.
p=9967; g=33;
A=7025;
% Alice’s public number
b=557;
% Bob’s secret
k=powermod(A,b,p) % secret key, =4133
c=4148;
% encrypted hour
h=bitxor(k,c)
% 17
Exercise 12.7
Eve knows the public key (n, e) and tries to find the prime factors of n with MATLAB’s built-in function factor() to find the prime factors, here p = 67 and
q = 83. Note that this would practically take forever for very large numbers n.
It works her, because n is rather small. Knowing p and q, Eve then calculates the
totient φ n and uses it to solve Bezout’s equation to determine the private key d, which
she subsequently uses to decode the message and finds that the meeting is at 11.
c=5343;
% encoded hour
n=5561; e=5;
a=factor(n); p=a(1); q=a(2); % crack
phin=(p-1)*(q-1)
% totient
[gcdval,d,kk]=gcd(e,phin) % coprime -> gcdval must be 1!
if gcdval ˜= 1 disp(’Error: not coprime’); return; end
d=powermod(d,1,phin)
% decryption key
decoded=powermod(c,d,n)
% decoded message, =11
Exercise 12.8
Bob has to collect all variables needed to calculate Q from (12.35) and then compare
its x-coordinate with r , provided as part of the signature. The following code snippet
shows how Bob first converts the message m to numerical form and then determines
the hash h. He then uses (12.34) to calculate the inverse of the other part of the
signature s and finds h/s and r/s before he uses the function ECCadd_p() from
Appendix B.11 to calculate (h/s) G and (r/s) P. Adding both contributions
yields Q. The first component of Q turns out to be equal to r = 66 and therefore the
message is authentic.
13 Solutions for Selected Exercises
Exercise 12.6
The following code snippet illustrates the communication between Alice and Bob.
After defining p and g, Bob uses Alice’s public number A and his secret number b
to calculate the encryption key k = A
b
(mod p) that he subsequently uses to decode
the ciphertext c. He finds that the plan is to meet at 17, or 5 pm.
p=9967; g=33;
A=7025;
% Alice’s public number
b=557;
% Bob’s secret
k=powermod(A,b,p) % secret key, =4133
c=4148;
% encrypted hour
h=bitxor(k,c)
% 17
Exercise 12.7
Eve knows the public key (n, e) and tries to find the prime factors of n with MATLAB’s built-in function factor() to find the prime factors, here p = 67 and
q = 83. Note that this would practically take forever for very large numbers n.
It works her, because n is rather small. Knowing p and q, Eve then calculates the
totient φ n and uses it to solve Bezout’s equation to determine the private key d, which
she subsequently uses to decode the message and finds that the meeting is at 11.
c=5343;
% encoded hour
n=5561; e=5;
a=factor(n); p=a(1); q=a(2); % crack
phin=(p-1)*(q-1)
% totient
[gcdval,d,kk]=gcd(e,phin) % coprime -> gcdval must be 1!
if gcdval ˜= 1 disp(’Error: not coprime’); return; end
d=powermod(d,1,phin)
% decryption key
decoded=powermod(c,d,n)
% decoded message, =11
Exercise 12.8
Bob has to collect all variables needed to calculate Q from (12.35) and then compare
its x-coordinate with r , provided as part of the signature. The following code snippet
shows how Bob first converts the message m to numerical form and then determines
the hash h. He then uses (12.34) to calculate the inverse of the other part of the
signature s and finds h/s and r/s before he uses the function ECCadd_p() from
Appendix B.11 to calculate (h/s) G and (r/s) P. Adding both contributions
yields Q. The first component of Q turns out to be equal to r = 66 and therefore the
message is authentic.
