Created
August 5, 2015 08:41
-
-
Save lepoetemaudit/6f17c74bc8fa7297fa7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Extremely crude example of a timing attack | |
""" | |
import time | |
import timeit | |
actualPassword = '0BEA0239' | |
def checkpassword(passwd): | |
for a, b in zip(passwd, actualPassword): | |
if a != b: | |
return False | |
if len(actualPassword) != len(passwd): | |
return False | |
return True | |
possibleDigits = 'ABCDEF0123456789' | |
password = '' | |
while True: | |
timings = {} | |
digits = [] | |
for i in possibleDigits: | |
newpassword = password + i | |
t = timeit.Timer(lambda: checkpassword(newpassword)) | |
digits.append((t.timeit(number=30000), str(i))) | |
probable_digit = sorted(digits)[-1][1] | |
password += str(probable_digit) | |
print("Found digit %s, trying password %s" % (probable_digit, password)) | |
if checkpassword(password): | |
print("Cracked the password!") | |
break | |
else: | |
print("Not found it yet, carrying on") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment