Created
June 10, 2010 16:26
-
-
Save errzey/433244 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
#!/usr/bin/python | |
from itertools import izip, cycle | |
import string, sys | |
def ascii_analysis(data): | |
total_len = len(data) | |
total_ascii = 0 | |
for char in data: | |
if char in string.ascii_letters or char in ['\r', '\n'] or char in string.digits or char in string.whitespace: | |
total_ascii += 1 | |
return (float(total_ascii) / float(total_len)) * float(100) | |
def xor_crypt(data, k): | |
return ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(k))) | |
def crack(infile, wordlist): | |
try: | |
f = open(infile, 'rb') | |
except: | |
print "couldn't open input file for reading" | |
sys.exit(1) | |
try: | |
wl = file(wordlist) | |
except: | |
print "Couldn't open wordlist for reading" | |
sys.exit(1) | |
data = f.read() | |
word = wl.readline() | |
while word: | |
word = word.rstrip() | |
if not word: | |
word = wl.readline() | |
continue | |
check = xor_crypt(data, word) | |
prop = ascii_analysis(check) | |
if prop >= 85.0: | |
print "Password is most definitely %s" % word | |
print "------" | |
print check | |
sys.exit(1) | |
word = wl.readline() | |
if __name__ == '__main__': | |
if sys.argv[1] == 'test': | |
test_out = open(sys.argv[2] + ".xord", 'wb+') | |
test_in = open(sys.argv[2], 'r') | |
data = test_in.read() | |
xord = xor_crypt(data, "Abraham") | |
test_out.write(xord) | |
test_out.close() | |
df = open(sys.argv[2] + ".xord", 'rb') | |
d = df.read() | |
x = xor_crypt(d, "Abraham") | |
print x, ascii_analysis(x) | |
sys.exit(1) | |
crack(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment