Created
July 21, 2009 09:02
-
-
Save gabriel/151215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lowest: | |
(31) bUGs BUgs bUGS bUgS bLAnk BlAnK BlANK BLank buGS bugS bUGS bUGs dCao2 ; from hashbreaker | |
(31) lINeS lInUX ligHTtpD lIb leheY LIBRaRY libcRyPt linK layer LeSK linus laYOuT \j|39 ; from dariencrane | |
(31) LehEy LENGtH layoUt liB liGhTTpD liFo lISp lIBRARy LInk LIBcRYpt LesS lAYER =@zT= ; from seibert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import log | |
from sys import argv, maxint | |
import hashlib | |
#import json | |
import simplejson as json | |
import httplib | |
def hamming(a, b, bits=160): | |
x = a ^ b | |
return sum((x >> i & 1) for i in xrange(bits)) | |
def asciify(s): | |
return s.encode('ASCII', 'replace') | |
contest_hash = "1249c4b7f578204f10798c0269f8488280fb9981" | |
lowest = [(maxint, None, None)] | |
for page in xrange(20): | |
print "Page: %s" % (page+1) | |
conn = httplib.HTTPConnection("search.twitter.com") | |
conn.request("GET", "/search.json?q=+to%%3Aengineyard&page=%s" % (page+1)) | |
res = conn.getresponse() | |
data = res.read() | |
conn.close() | |
results = json.loads(data) | |
for result in results['results']: | |
entry = asciify(result['text'][12:].strip()) | |
from_user = result['from_user'] | |
user_hash = hashlib.sha1(entry).hexdigest() | |
distance = hamming(long(contest_hash, 16), long(user_hash, 16)) | |
if distance == 0: continue | |
if distance < lowest[0][0]: | |
lowest = [(distance, entry, from_user)] | |
elif distance == lowest[0][0]: | |
lowest.append((distance, entry, from_user)) | |
print "(%s) %s ; from %s" % (distance, entry, from_user) | |
print "\n\nLowest:" | |
for low in lowest: | |
print "\t(%s) %s ; from %s" % low |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import log | |
from sys import argv | |
import hashlib | |
def hamming(a, b, bits=160): | |
x = a ^ b | |
return sum((x >> i & 1) for i in xrange(bits)) | |
if __name__ == "__main__": | |
contest_hash = "1249c4b7f578204f10798c0269f8488280fb9981" | |
user_string = ' '.join(argv[1:]) | |
user_hash = hashlib.sha1(user_string).hexdigest() | |
distance = hamming(long(contest_hash, 16), long(user_hash, 16)) | |
print "Distance: %s" % distance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment