Skip to content

Instantly share code, notes, and snippets.

@nemanjan00
Created December 4, 2022 00:26
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 nemanjan00/f7b90e87436ecda46832959baa8600e1 to your computer and use it in GitHub Desktop.
Save nemanjan00/f7b90e87436ecda46832959baa8600e1 to your computer and use it in GitHub Desktop.
import matplotlib.pylab as plt
import chipwhisperer as cw
import time
tries = 0
scope = cw.scope()
target_type = cw.targets.SimpleSerial
target = cw.target(scope, target_type)
scope.default_setup()
def reset_target(scope):
scope.io.pdic = 'low'
time.sleep(0.1)
scope.io.pdic = 'high_z' #XMEGA doesn't like pdic driven high
time.sleep(0.1) #xmega needs more startup time
scope.adc.samples = 500
def cap_pass_trace(pass_guess):
reset_target(scope)
num_char = target.in_waiting()
while num_char > 0:
target.read(num_char, 10)
time.sleep(0.01)
num_char = target.in_waiting()
scope.arm()
target.write(pass_guess)
ret = scope.capture()
if ret:
print('Timeout happened during acquisition')
trace = scope.get_last_trace()
return trace
password = ""
valid = "abcdefghijklmnopqrstuvwxyz0123456789"
for i in range(5):
trace_a = cap_pass_trace(password + "\x00\n")
cur_key = "\0x0"
cur_max = 0
for char in valid:
tries = tries + 1
trace_h = cap_pass_trace(password + char + "\n")
score = sum(abs(trace_a - trace_h))
# print(password + char, score)
if score > cur_max:
cur_max = score
cur_key = char
password += cur_key
print(password)
print(password, tries)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment