Skip to content

Instantly share code, notes, and snippets.

@spiiin
Created October 12, 2014 13:07
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 spiiin/1882d49b7f21961b7aee to your computer and use it in GitHub Desktop.
Save spiiin/1882d49b7f21961b7aee to your computer and use it in GitHub Desktop.
find longest sequence of 8-multiple values
import os
fn = os.path.expanduser("~/desktop/dump.bin")
with open(fn, "rb")as f:
d = f.read()
d = map(ord, d)
def repWord(d):
ans = []
for x in xrange(0,len(d),2):
ans.append(d[x]*256+d[x+1])
return ans
dd = repWord(d)
def findLongest(dd):
ans = []
x = 0
startAddr = 0
curLen = 0
while x < len(dd):
val = dd[x]
if val % 8 == 0:
curLen += 1
else:
if curLen > 10:
ans.append((startAddr,curLen))
startAddr = x
curLen = 0
x+=1
return ans
ans = findLongest(dd)
ans.sort(key=lambda v:v[1])
for x in ans:
print x
(5247, 11040)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment