summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2016-08-13 17:19:00 +0200
committerRahiel Kasim <rahielkasim@gmail.com>2016-08-13 17:19:00 +0200
commit310a442989335edf24b914c5a54e71684840e17e (patch)
treea133d4e654642d4aabf02e6b51107d7f31acf1cf
parentfb38e353fac0cdf2da0b62e61750ed77c453ba3c (diff)
30: never use the time to generate keys
-rw-r--r--30-bad-entro.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/30-bad-entro.py b/30-bad-entro.py
new file mode 100644
index 0000000..fa91cc6
--- /dev/null
+++ b/30-bad-entro.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+# uses pycrypto, python3-crypto in Debian
+from datetime import datetime
+from hashlib import md5
+
+from Crypto.Cipher import AES
+from tqdm import tqdm
+
+
+ciphertext = 0xa99210d796a1e37503febf65c329c1b2
+c = ciphertext.to_bytes(16, byteorder="big")
+
+def is_ascii_printable(text):
+ return all([32 <= x <= 126 for x in text])
+
+start = int(datetime(2016, 1, 24).timestamp())
+end = int(datetime(2016, 1, 31).timestamp())
+
+for i in tqdm(range(start, end)):
+ key = md5(str(i).encode("ascii")).digest()
+ cipher = AES.new(key, AES.MODE_ECB)
+ m = cipher.decrypt(c)
+ if is_ascii_printable(m):
+ solution = m.decode("ascii")
+ break
+
+print(solution)