Skip to content

Commit

Permalink
9: crypto is insecure if you use small keys
Browse files Browse the repository at this point in the history
  • Loading branch information
rahiel committed Aug 26, 2016
1 parent 310a442 commit 4318daa
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions 09-insufficient-key-size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from utils import mod_inv

# Read modulus and exponent from public-key with openssl:
# openssl rsa -RSAPublicKey_in -in 09-unsufficient-key-size.key -text
e = 65537
modulus = int("70:18:f7:17:fc:66:65:15:0c:14:88:54:f6:4c:49".replace(":", ""), 16)

# factorize modulus with WolframAlpha:
# https://www.wolframalpha.com/input/?i=factor+582043602765817436229812959722228809
p, q = 662700133751480051, 878291059745115859
assert p * q == modulus

phi = (p - 1) * (q - 1)
d = mod_inv(e, phi)

solution = hex(d)[2:]
print(solution)

0 comments on commit 4318daa

Please sign in to comment.