7CCSMCIS Cryptography and Information Security

Coursework 4
MSc Computing and Security
13 min read

What is a one-way function and what are its properties?

A function f:XY is a one-way function, if f is easy to compute for all xX but f1 is hard (or infeasible) to compute.

What is a trapdoor one-way function? Give one example.

A trapdoor one-way function fk:XY is a one-way function where given the k it becomes feasible to compute fk1 but is infeasible otherwise.
e.g. modular cube roots when we know p and q .


Use both Euclid’s algorithm and Extended Euclid’s algorithm to compute gcd(1970,1066) , showing all steps of the computations.

Euclid(a, b):
    if b == 0:
        return a
    else
        return Euclid(b, a % b)

Extended Euclid’s (Unravelling):

Remember:

  • d=di1
  • x=yi1
  • y=xi1(q×x)
abq=[a/b]dxy
1970106612204173(1×204)=377
10669041217331(1×173)=204
904162523118(5×31)=173
16294121813(1×18)=31
946812135(1×13)=18
68262253(2×5)=13
26161232(1×3)=5
16101221(1×2)=3
1061211(1×1)=2
641210(1×1)=1
421201(2×0)=1
20210

Consider the primes p=11 and q=23 .
Calculate n and ϕ(n)

For this we should know:

  • n=pq
  • ϕ(n)=(p1)(q1)
n=11×23=253
ϕ(n)=(111)(231)=10×22ϕ(n)=220

Explain which of the values e=3 or e=5 is usable as a public key for this given n .

We have to choose an e where gcd(ϕ(n),e)=1 and 1<e<ϕ(n) .

Let’s try gcd(220,3) first.

abq=[a/b]dxy
220373
313
10

As we can see, gcd(220,3)=1 . Let’s try gcd(220,5) just to show the difference.

abq=[a/b]dxy
220544
50

As we can see, gcd(220,5)=5 , therefore e=5 is NOT suitable. e=3 is suitable.

Use the Extended Euclid’s algorithm to calculate d with the e you have chosen.

We find our d by finding the top value of y in our previous table. We use the following rules (going backwards)

  • d=di1
  • x=yi1
  • y=xi1(q×x)
abq=[a/b]dxy
220373110(73×1)=73
313101(3×0)=1
10110

We get y=73 , therefore d=73mod220=247 .

Encrypt M=165 and then decrypt the resulting ciphertext.

We use C=Memodn .

C=1653mod253C=

Decryption:

Using M=Cdmodn .

M=C147mod253M=

Consider the RSA algorithm with n=55 and e=7 .

  • Encipher the plaintext M=10 .

Use C=Memod55 .

  • Break the cipher by finding p , q and d .

We know:

  • n=pq , n=55

We can guess p=5 , q=11 as 2 primes.

  • ϕ(n)=(p1)(q1)=40

To find d , we know d=e1modϕ(n) .

d=71mod40 . We can use Extended-Euclid’s Algorithm.

abq=[a/b]dxy
4075132(5×3)=17
751121(1×2)=3
522110(2×1)=2
212101(2×0)=1
10110

We have y=17 , therefore d=17mod40=23 .


Perform encryption and decryption using the RSA algorithm for the following:

p=3 , q=11 , d=7 , M=5

  1. n=pq=33
  2. ϕ(n)=(p1)(q1)=20
  3. Select e such that gcd(ϕ(n),e)=1 and 1<e<ϕ(n) .
  4. Use Extended-Euclid’s algorithm to find d .

Let’s try e=3

abq=[a/b]dxy
2036111(6×1)=7
321110(1×1)=1
212101(2×0)=1
10110

gcd(20,3)=1 , therefore e=3 is a good candidate. y=7 , therefore d=7mod20=7 .

Encryption:

We know C=Memodn

C=53mod33=125mod33C=26

Decryption:

We know M=Cdmodn

M=267mod33=(262×262×262×26)mod33=(676×676×676×26)mod33=(16×16×16×26)mod33=(256×16×26)mod33=(25×16×26)mod33=(650×16)mod33=(23×16)mod33=(23×16)mod33=368mod33M=5

p=5 , q=11 , e=3 , M=9

  1. n=pq=55
  2. ϕ(n)=(p1)(q1)=40
  3. Select e such that gcd(ϕ(n),e)=1 and 1<e<ϕ(n) . e=3
  4. Use Extended-Euclid’s algorithm to find d .
abq=[a/b]dxy
40313110(13×1)=13
313101(3×0)=1
10110

y=13 , therefore d=13mod40=27

Encryption:

We know: C=Memodn

C=93mod55=(92×9)mod55=(26×9)mod55=234mod55C=14

Decryption:

We know: M=Cdmodn

M=1427mod55=9

Consider the RSA algorithm with p=7 , q=3 and e=5 .

Encipher the plaintext M=4 .

We know:

  • C=Memodn
  • n=pq=21
C=45mod21=(43×42)mod21=(64×16)mod21=(1×5)mod21C=16

Decipher the resulting ciphertext C to obtain again M .

We know:

  • M=Cdmodn
  • d=e1modϕ(n)
  • ϕ(n)=(p1)(q1)=12
d=51mod12
abq=[a/b]dxy
1252121(2×2)=5
522110(2×1)=2
212101(2×0)=1
10110

y=5 , therefore d=5mod12 .

Decryption:

M=Cdmodn
M=165mod21=(162×162×16)mod21=(172×172×16)mod21=(4×4×16)mod21=(16×16)mod21=172mod21M=4

Why are these p=7 , q=3 and e=5 not really a good choice for RSA?

They are very small numbers which can be brute-forced quite quickly. Normally RSA will use numbers represented by 1024+ bits.


Consider a Diffie-Hellman key exchange with α=2 , q=11 , XA=9 , XB=3 . Compute YA and YB , and the secret key K .

We know:

  • YA=αXAmodq
  • YB=αXBmodq
  • KA=YBXAmodq
  • KB=YAXBmodq
YA=29mod11=(24×24×2)mod11=(5×5×2)mod11=50mod11YA=6
YB=23mod11=8mod11YB=8
KA=89mod11=(82×82×82×82×8)mod11=(92×92×8)mod11=(42×8)mod11=(5×8)mod11KA=7
KB=63mod11=(62×6)mod11=(3×6)mod11KB=7

Therefore K=7 .

Consider a Diffie-Hellman scheme with α=3 , q=17 , XA=7 , XB=4 . Compute YA and YB , and the secret key K .

We know:

  • YA=αXAmodq
  • YB=αXBmodq
  • KA=YBXAmodq
  • KB=YAXBmodq
YA=37mod17=(33×33×3)mod17=(10×10×3)mod17=(10×13)mod17YA=11
YB=34mod17=(33×3)mod17=(10×3)mod17YB=13
KA=137mod17=(132×132×132×13)mod17=(162×16×13)mod17=(1×16×13)mod17KA=4
KB=114mod17=(112×112)mod17=2×2mod17KB=4

Describe the man-in-the-middle attack to the Diffie-Hellman key exchange and how it could be prevented.

As Diffie-Hellman doesn’t provide authentication, any attacker, Charlie, could place themselves inbetween unsuspected agents, Alice and Bob. Charlie can complete the DH protocol with both Alice and Bob by intercepting their messages and establish a shared key for Alice and a separate shared key for Bob.

This attack can prevented by the use of digital signature schemes.

Describe the Diffie-Hellman key exchange protocol for three honest principals Alice, Bob and Carol. What would be the secret key for n principals A1,A2,...An ?

  1. Alice, Bob and Carol all generate their random large private integer XA , XB , XC respectively and calculate their public integer Yi=αXimodq .
  2. Each agent sends another agent’s public integer raised with their private key to another agent (in a circular chain).
  • Alice sends Carol’s public integer raised with her private integer ( YCXAmodq ) to Bob.
  • Bob sends Alice’s public integer raised with his private integer ( YAXBmodq ) to Carol.
  • Carol sends Bob’s public integer raised with her private integer ( YBXCmodq ) to Alice.
  1. Each agent calculates the shared key by raising what they receivied with their private integer.
  • Alice calculates K=YBXCXAmodq .
  • Bob calculates K=YCXAXBmodq .
  • Carol calculates K=YAXAXCmodq .

Describe the El Gamal algorithm

El Gamal is a sped up version of DH where agent B , can respond to A with an encrypted message. In the following protocol:

  1. AB:YA . A calculates YA=αXAmodq and sends it to $$B$.
  2. BA:(E(M,K),YB) . B calculates YB=αXBmodq AND computes the shared key KB=YAXBmodq and uses it to encrypt a message M .
  3. A calculates YBXAmodq to get the shared key K .

Consider the El Gamal algorithm with α=5 , q=13 , XA=7 , XB=9 .

Consider the plaintext M=5 and let symmetric encryption be just the multiplication of the plaintext and the key (not a good encryption, of course, but that is not the point here).

Carry out the algorithm (for encryption).

YA=αXAmodqAB:YAKB=YAXBmodqYB=αXBmodqE(M,K)=KMBA:(E(M,KB),YB)KA=YBXAmodq
YA=57mod13=(52×52×52×5)mod13=(122×12×5)mod13=(1×60)mod13=5AB:5KB=59mod13=(53×53×53)mod13=(82×8)mod13=(12×8)mod13=96mod13=5YB=59mod13=5E(M,K)=5×5=25BA:(25,5)KA=57mod13=5

Why are these α=5 , q=13 , XA=7 , XB=9 not adequate for El Gamal? Where is the problem? Would α=3 or α=4 be better?

They result in all of the keys being 5 .


Explain in detail the main characteristics of cryptographic hash functions and give an example of an application.

The motivation behind hash functions is to create a fingerprint. A hash function, h(x) has the properties:

  • Compression: h maps an input x of arbitrary bit length to an output h(x) of fixed bit length n .
  • Polynomial time computable.

A cryptographic hash function is additionally:

  • One-way (where given y , it is hard to compute an x where h(x)=y ).
  • And either:
  • 2nd-preimage resistant: it is computationally infeasile to find a second input that has the same output as any specified input.
  • Collision resistant: it is difficult to find two distinct inputs x , x where h(x)=h(x) .

Explain in detail how Message Authentication Codes (MAC) work.

Bob and Alice both share a secret key k . Alice uses a one-way hash function with parameter k to hash a message m to obtain a MAC. Alice sends this MAC along with her message m to Bob who then attempts to calculate the same MAC with k and m in the one-way hash function. He compares his result with the MAC Alice sent and if they match, it’s valid. If they don’t, he cannot trust the message.

Explain in detail the main characteristics of a digital signature scheme. How can RSA be used for digital signatures?

Digital signatures take advantage of reversible public-key cryptosystems. A message can be encrypted with Alice’s private key; thus anyone with Alice’s public key (everyone) can decrypt the message, proving it was sent by Alice.