•
5 min read
Solving Cryptography Problems - 3

Here’s the next problem:

The public key is N=209N=209. What is the Rabin decryption of 8080?

  • What is Rabin decryption?
    wikipedia: The Rabin cryptosystem is an asymmetric cryptographic technique, whose security, like that of RSA, is related to the difficulty of integer factorization. However the Rabin cryptosystem has the advantage that it has been mathematically proven to be computationally secure against a chosen-plaintext attack as long as the attacker cannot efficiently factor integers, while there is no such proof known for RSA.

  • What is a chosen plaintext attack?
    wikipedia: A chosen-plaintext attack (CPA) is an attack model for cryptanalysis which presumes that the attacker can obtain the ciphertexts for arbitrary plaintexts. The goal of the attack is to gain information that reduces the security of the encryption scheme.

  • How does the Rabin Encryption scheme work?
    wikipedia: The keys for the Rabin cryptosystem are generated as follows:

    1. Choose two large distinct prime numbers pp and qq such that p≡3 mod 4p\equiv 3\bmod 4 and q≡3 mod 4q\equiv 3\bmod 4.
    2. Compute n=pqn=pq. Then nn is the public key and the pair (p,q)(p,q) is the private key.
  • Decryption
    Since 209 is not a large number, we can easily factorise it through trial and error:

i = 2
while 209 % i != 0: i+=1
print(i, 209/i)

11 19.0

Let p=11p=11 and q=19q=19. Now, following the procedure from wikipedia,

The message mm can be recovered from the ciphertext 8080 by taking its square root modulo 209209 as follows.

  1. Compute the square root of cc modulo pp and qq:

    mp=8014(11+1) mod 11=5mq=8014(19+1) mod 19=17\begin{aligned} m_p &= 80^{\frac{1}{4}(11+1)} \bmod{11} = 5 \\ m_q &= 80^{\frac{1}{4}(19+1)} \bmod{19} = 17 \end{aligned}
  2. Using the extended Euclidean algorithm to find ypy_p and yqy_q such that

    yp⋅p+yq⋅q=1y_p \cdot p + y_q \cdot q = 1
    def ExtEuclid (a,b):
    # returns a triple (d,s,t) such that d = gcd(a,b) and
    # d == a*s + b*t
    if b == 0: return (a,1,0)
    (d1, s1, t1) = ExtEuclid(b,a%b)
    d = d1
    s = t1
    t = s1 - int(a / b) * t1
    return (d,s,t)
    
    print('{} = 19*({}) + 11*({})'.format(*ExtEuclid(19,11)))

    1 = 19*(-4) + 11*(7)

    So we have yp=7y_p = 7 and yq=−4y_q = -4.
    These two articles (this one and this one) were useful in understanding the algorithm.

  3. Using the Chinese remainder theorem to find the four square roots of cc modulo nn:

    r1=(7⋅11⋅17+(−4)⋅19⋅5) mod 209=93r2=209−93=116r3=(7⋅11⋅17−(−4)⋅19⋅5) mod 209=17r4=209−17=192\begin{aligned} r_1 &= (7 \cdot 11 \cdot 17 + (-4) \cdot 19 \cdot 5) \bmod 209 = 93\\ r_2 &= 209 - 93 = 116\\ r_3 &= (7 \cdot 11 \cdot 17 - (-4) \cdot 19 \cdot 5) \bmod 209 = 17\\ r_4 &= 209 - 17 = 192 \end{aligned}

    One of these four values is the original plaintext mm, although which of the four is the correct one cannot be determined without additional information.
    Of these four, 9393 is the only value that matches an option in my assignment, which means that it is the original plaintext in this case.

Further Reading / Questions:

Here’s the next one:

The public key is N=713N = 713. What is the Rabin Digital Signature of 473473?

  • What is the Rabin Signature Scheme?
    From my class notes,
    Signature: s=m1/2 mod ns = m^{1/2} \bmod n where ss is the signature
    Verification: m=s2 mod nm = s^2 \bmod n

Now I can think of two ways to solve this:

  • the one where we use pen and paper

    x2≡473 mod 713x^2 \equiv 473 \bmod 713
      ⟹  x2≡473 mod 23\implies x^2 \equiv 473 \bmod 23 and x2≡473 mod 31x^2 \equiv 473 \bmod 31
      ⟹  x2≡13 mod 23\implies x^2 \equiv 13 \bmod 23 and x2≡8 mod 31x^2 \equiv 8 \bmod 31
      ⟹  x2≡36 mod 23\implies x^2 \equiv 36 \bmod 23 and x2≡225 mod 31x^2 \equiv 225 \bmod 31
      ⟹  x≡±6 mod 23\implies x \equiv \pm 6 \bmod 23 and x≡±15 mod 31x \equiv \pm 15 \bmod 31

    We can then solve the four sets of equations using the Chinese Remainder theorem. These two videos (this one and this one) helped me in this approach.

  • the one where we use a brute force approach

    i = j = 1
    while j <= 4:
        while i**2 % 713 != 473: i+=1
        print(i)
        i+=1
        j+=1

Either way, the four roots we get are: 109109, 201201, 512512 and 604604.

Of these four, 201201 is the only one present in the given options in my assignment, so that is the solution to this problem.

Further Reading / Questions:

I clearly need to read more about Rabin’s cryptosystem, because the knowledge I have currently is not complete. I don’t want to make any commitments, except that if I encounter it again I’ll try to gain an in depth understanding of the cryptosystem and the problem solving techniques it involves (such as the Chinese remainder theorem).

Until next time!