def test_rsa_broadcast_icectf(self):
'''Special case where a standard broadcast attack will not work because plaintext is bigger than any of the provided modulus. '''
'''Every individual RSA encryption loses some information, but when enough pubkeys and ciphertexts are gathered, the plaintext can be "magically" recovered. '''
'''http://blog.atx.name/icectf/#Agents'''
exponent = 3
ns = []
for _ in range(200):
_, (n, e) = keygen_rsa(1024, exponent)
ns.append(n)
# making sure msg is bigger than the biggest modulus
msg = 'the secret msg is '
while not bytes_to_long(msg) > max(ns):
msg += random_chars(1)
msg += random_chars(1000)
pairs = []
for n in ns:
ct = encrypt_rsa((n, exponent), bytes_to_long(msg))
pairs.append((n, ct))
rec = rsa_broadcast_attack(pairs)
self.assertTrue(rec == msg)
评论列表
文章目录