Create a gist now

Instantly share code, notes, and snippets.

Python script to solve traces from 32c3
#!/usr/bin/env python
valid = False
fw = None
x = 0
y = 0
# Guess that width is 752 pixels, try some different widths
width = 752
xline = []
def output_val(val):
global valid
global x
global y
global xline
"""
First 2 bits are Line valid and Frame valid.
When both are 1, start writing new image.
End when both are not 1.
"""
if (valid == False) and (val[:2] == '11'):
# line start
xline = []
valid = True
if (valid == True) and (val[:2] == '11'):
# Write one pixel
# Convert 10-bit pixeldata to 8-bit
# by dividing by 4
if x < width:
pixel = int(val[2:], 2) // 4
xline.append(chr(pixel))
x += 1
if (valid == True) and (val[:2] != '11'):
# line end
while x < width:
# Append 0:s if line < 752 pixels
xline.append(chr(0))
x += 1
for c in xline:
fw.write(c)
x = 0
valid = False
y += 1
fd = open('clean.csv', 'r')
fw = open('output.data', 'wb')
old = 10
new = 0
for line in fd:
l = line.split()
# Ignore bad lines
if len(l) < 2:
continue
new = float(l[0])
if new >= 1.5 and old < 1.5:
# positive flank
output_val(l[1])
old = new
# break after 1024 lines
if y >= 1024:
break
fd.close()
fw.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment