cryptopal.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:cryptopal 作者: lanjelot 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号