summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2016-08-26 09:28:05 +0200
committerRahiel Kasim <rahielkasim@gmail.com>2016-08-26 09:28:05 +0200
commit4318daaa0f8dd0344796a936c9a2d307117e87fa (patch)
tree1da68ac52ac10003a92545274705ab11e1cf7cec
parent310a442989335edf24b914c5a54e71684840e17e (diff)
9: crypto is insecure if you use small keys
-rw-r--r--09-insufficient-key-size.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/09-insufficient-key-size.py b/09-insufficient-key-size.py
new file mode 100644
index 0000000..b313986
--- /dev/null
+++ b/09-insufficient-key-size.py
@@ -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)