Skip to content

Instantly share code, notes, and snippets.

@EmilHernvall
Created April 7, 2012 22:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EmilHernvall/2332678 to your computer and use it in GitHub Desktop.
Save EmilHernvall/2332678 to your computer and use it in GitHub Desktop.
import urllib2
import re
import base64
def searchForNext(str, unique):
d = 10
last = str[-d:]
print "searching for continuation of " + last
matches = []
for x in unique:
pos = x.find(last)
if pos != -1: matches.append((pos,x))
print "matches: %d" % (len(matches))
if not matches: return None
matches.sort(lambda x,y: x[0]-y[0])
match = matches[0]
return match[1][match[0]+d:]
data = urllib2.urlopen("https://raw.github.com/gist/4a65eadfbdc81b5eeb43/3591eb5
exp = re.compile(r'([0-9abcdef]{100})')
matches = exp.findall(data)
unique = list(set(matches))
unique.sort()
result = "497a78705032357759326873634855675a43526c595341675044317a494852685a484a
while True:
next = searchForNext(result, unique)
if not next: break
result += next
print "hex: " + result
f = lambda s: "".join([chr(int(s[i:i+2],16)) for i in xrange(0, len(s)) if i % 2
result = f(result)
print "base64: " + result
for i in xrange(0,3):
try:
print result
result = base64.b64decode(result)
print "success: " + result
break
except TypeError:
result += "="
result1 = "".join([result[x] for x in xrange(0, len(result)) if x % 2 == 0])
result2 = "".join([result[x] for x in xrange(0, len(result)) if x % 2 == 1])
print result1
print result2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment