Skip to content

Instantly share code, notes, and snippets.

@yasyf
Last active December 15, 2015 15:48
Show Gist options
  • Save yasyf/5284058 to your computer and use it in GitHub Desktop.
Save yasyf/5284058 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import urllib
import urllib2
import re
wordlists = ["/path/to/your/wordlist.txt"]
def regex(txt):
re1='.*?' # Non-greedy match on filler
re2='(\\d+)' # Integer Number 1
rg = re.compile(re1+re2,re.IGNORECASE|re.DOTALL)
m = rg.search(txt)
if m:
int1=m.group(1)
return int1
def run(word):
word=word.rstrip()
url = "http://almamater.xkcd.com/?edu=mit.edu"
data = urllib.urlencode({'hashable': word})
result = urllib2.urlopen(url, data)
lines = result.read().split("<br>")
return word+" : "+regex(lines[1])
log = open('xkcd.txt','a')
i = 0
for file in wordlists:
f = open(file,"rU")
for line in f:
log.write(run(line)+"\n")
if i > 10:
log.flush()
i = 0
i += 1
print run(line)
#!/usr/bin/env python3
import multiprocessing, signal, time, skein, random, urllib.request, urllib.parse
TARGET = '5b4da95f5fa08280fc9879df44f418c8f9f12ba424b7757de02bbdfbae0d4c4fd' + \
'f9317c80cc5fe04c6429073466cf29706b8c25999ddd2f6540d4475cc977b87f4757be' + \
'023f19b8f4035d7722886b78869826de916a79cf9c94cc79cd4347d24b567aa3e2390' + \
'a573a373a48a5e676640c79cc70197e1c5e7f902fb53ca1858b6'
TARGET = int(TARGET, 16)
RND_BIT_LEN = 512
def init_worker():
signal.signal(signal.SIGINT, signal.SIG_IGN)
def run_worker():
r = random.SystemRandom()
best = 430
while True:
dat = hex(r.getrandbits(RND_BIT_LEN))[2:].encode('ascii')
h = int(skein.skein1024(dat).hexdigest(), 16)
diff = bin(h ^ TARGET).count('1')
if diff < best:
best = diff
log = open('xkcd_local.txt','a')
submit(dat.decode('ascii'),diff,log)
log.close()
def submit(word,diff,log):
url = "http://almamater.xkcd.com/?edu=mit.edu"
data = urllib.parse.urlencode({'hashable': word})
binarydata = data.encode('ascii')
urllib.request.urlopen(url, binarydata)
result = '%s : %s' % (word, diff)
print(result)
print(result,end="\n", file=log)
log.flush()
def main():
cpus = multiprocessing.cpu_count()
pool = multiprocessing.Pool(cpus, init_worker)
for i in range(cpus):
pool.apply_async(run_worker)
try:
while True:
time.sleep(100)
except KeyboardInterrupt:
print('Terminating...')
pool.terminate()
pool.join()
else:
print('Quitting...')
pool.close()
pool.join()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment