Skip to content

Instantly share code, notes, and snippets.

@lepoetemaudit
Created August 5, 2015 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lepoetemaudit/6f17c74bc8fa7297fa7f to your computer and use it in GitHub Desktop.
Save lepoetemaudit/6f17c74bc8fa7297fa7f to your computer and use it in GitHub Desktop.
"""
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