RSA Stream

RSA common modulus attack

Description

I made a stream cipher out of RSA! But people say I made a huge mistake. Can you decrypt my cipher?

Solution

The cipher is the result of stream ^ q. Since q is known, we can reverse the stream:

import gmpy2
from Crypto.Util.number import long_to_bytes, bytes_to_long, getStrongPrime, inverse
from Crypto.Util.Padding import pad

with open("chal.enc", "rb") as f:
    cipher = f.read()

f = open("chal.py","rb").read()

e = 0x10001
for a in range(0,len(f),256):
  q = f[a:a+256]
  if len(q) < 256:q = pad(q, 256)
  q = bytes_to_long(q)
  c = cipher[a:a+256]
  c = bytes_to_long(c)

  stream = c ^ q
  print('e =', e)
  print('stream =', stream)

  e = gmpy2.next_prime(e)

The values of e are also known. Since the same modulus is used for each value of e, we can perform a common modulus attack:

ACSC{changing_e_is_too_bad_idea_1119332842ed9c60c9917165c57dbd7072b016d5b683b67aba6a648456db189c}

Last updated

Was this helpful?