jvdsn / crypto-attacks

Python implementations of cryptographic attacks and utilities.
MIT License
888 stars 114 forks source link

Fix common modules attack #15

Closed weyung closed 1 year ago

weyung commented 1 year ago

Add a situation when e1 and e1 have a small gcd.

jvdsn commented 1 year ago

Thanks for the PR. Do you have a test case for this enhancement?

weyung commented 1 year ago
def test_common_modulus(self):
    p = 7533786619797084306332779503584785720237908463304409345290805538825354595934248304351730420702977327869673269459606431198799644428816355505475872341745119
    q = 11736209613542675168896166783523457796515430159358741698291601755512636680940041591293981708617818996457987754784026535146391007150954925977654218732583633
    n = p * q
    e1 = 63
    c1 = pow(2, e1, n)
    e2 = 49
    c2 = pow(2, e2, n)
    m = common_modulus.attack(n, e1, c1, e2, c2)
    self.assertIsInstance(m, int)
    self.assertEqual(2, m)
jvdsn commented 1 year ago

Thanks, I had to make some adjustments but it works now.