-
-
Save AHAPX/b06d565b14bb478e70f966c31cb47413 to your computer and use it in GitHub Desktop.
kk.py
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
import os | |
import hashlib | |
import time | |
import math | |
import sys | |
# Main function | |
def decrypt(x, y): | |
# Variables corresponding to string indices, counter, starting point, completion, and starting time | |
i = 0 | |
ii = 0 | |
iii = 0 | |
iiii = 0 | |
iiiii = 0 | |
iiiiii = 0 | |
c = 0 | |
startPoint = 0 | |
complete = 0 | |
startTime = time.time() | |
# Set starting string (if given) | |
if (len(y) > 0): | |
# Ignore starting string if it is too long | |
if (len(y) > 6): | |
print "String too long, ignoring." | |
os.system('pause') | |
# Make sure every character of the string is in the list | |
elif (len(y) == 6 and y[0] in alpha and y[1] in alpha and y[2] in alpha and y[3] in alpha and y[4] in alpha and y[5] in alpha): | |
i = alpha.index(y[5]) | |
ii = alpha.index(y[4]) | |
iii = alpha.index(y[3]) | |
iiii = alpha.index(y[2]) | |
iiiii = alpha.index(y[1]) | |
iiiiii = alpha.index(y[0]) | |
startPoint = 5 | |
elif (len(y) == 5 and y[0] in alpha and y[1] in alpha and y[2] in alpha and y[3] in alpha and y[4] in alpha): | |
i = alpha.index(y[4]) | |
ii = alpha.index(y[3]) | |
iii = alpha.index(y[2]) | |
iiii = alpha.index(y[1]) | |
iiiii = alpha.index(y[0]) | |
startPoint = 4 | |
elif (len(y) == 4 and y[0] in alpha and y[1] in alpha and y[2] in alpha and y[3] in alpha): | |
i = alpha.index(y[3]) | |
ii = alpha.index(y[2]) | |
iii = alpha.index(y[1]) | |
iiii = alpha.index(y[0]) | |
startPoint = 3 | |
elif (len(y) == 3 and y[0] in alpha and y[1] in alpha and y[2] in alpha): | |
i = alpha.index(y[2]) | |
ii = alpha.index(y[1]) | |
iii = alpha.index(y[0]) | |
startPoint = 2 | |
elif (len(y) == 2 and y[0] in alpha and y[1] in alpha): | |
i = alpha.index(y[1]) | |
ii = alpha.index(y[0]) | |
startPoint = 1 | |
elif (len(y) == 1 and y[0] in alpha): | |
i = alpha.index(y[0]) | |
# Ignore starting string if it is not in the list | |
else: | |
print "String not in list, ignoring." | |
os.system('pause') | |
# First check null string | |
if (hashType == 'sha512'): | |
if (hashlib.sha1('').hexdigest() == x): | |
os.system('cls') | |
print "Trying: " + hashlib.sha1('').hexdigest() + " ()" | |
print "Combinations Tried: 1" | |
print "Success! Decrypted to: <null string> ()" | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
# To skip the next check | |
startPoint = 99 | |
if (hashType == 'sha256'): | |
if (hashlib.sha256('').hexdigest() == x): | |
os.system('cls') | |
print "Trying: " + hashlib.sha256('').hexdigest() + " ()" | |
print "Combinations Tried: 1" | |
print "Success! Decrypted to: <null string> ()" | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
# To skip the next check | |
startPoint = 99 | |
if (startPoint == 0 and i == 0): | |
c += 1 | |
# 1 character case (first check null string) | |
if (startPoint == 0): | |
skip_print = 0 | |
while (i < len(alpha)): | |
c += 1 | |
if skip_print == 0: | |
os.system('cls') | |
print "Decrypting: " + x | |
# SHA-512 | |
if (hashType == 'sha512'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha1(alpha[i]).hexdigest() + " (" + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha512(alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
# SHA256 | |
elif (hashType == 'sha256'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha256(alpha[i]).hexdigest() + " (" + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha256(alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
skip_print += 1 | |
skip_print %= 10000 | |
if (complete == 0): | |
startPoint = 1 | |
i = 0 | |
# 2 character case | |
if (startPoint == 1): | |
skip_print = 0 | |
while (ii < len(alpha)): | |
c += 1 | |
if skip_print == 0: | |
os.system('cls') | |
print "Decrypting: " + x | |
# SHA-512 | |
if (hashType == 'sha512'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha512(alpha[ii] + alpha[i]).hexdigest() + " (" + alpha[ii] + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha512(alpha[ii] + alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[ii] + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
if (i == len(alpha)): | |
i = 0 | |
ii += 1 | |
# SHA256 | |
elif (hashType == 'sha256'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha256(alpha[ii] + alpha[i]).hexdigest() + " (" + alpha[ii] + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha256(alpha[ii] + alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[ii] + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
if (i == len(alpha)): | |
i = 0 | |
ii += 1 | |
skip_print += 1 | |
skip_print %= 10000 | |
if (complete == 0): | |
i = 0 | |
ii = 0 | |
startPoint = 2 | |
# 3 character case | |
if (startPoint == 2): | |
skip_print = 0 | |
while (iii < len(alpha)): | |
c += 1 | |
if skip_print == 0: | |
os.system('cls') | |
print "Decrypting: " + x | |
# SHA-512 | |
if (hashType == 'sha1'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha512(alpha[iii] + alpha[ii] + alpha[i]).hexdigest() + " (" + alpha[iii] + alpha[ii] + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha512(alpha[iii] + alpha[ii] + alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[iii] + alpha[ii] + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
if (i == len(alpha)): | |
i = 0 | |
ii += 1 | |
if (ii == len(alpha)): | |
ii = 0 | |
iii += 1 | |
# SHA256 | |
elif (hashType == 'sha256'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha256(alpha[iii] + alpha[ii] + alpha[i]).hexdigest() + " (" + alpha[iii] + alpha[ii] + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha256(alpha[iii] + alpha[ii] + alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[iii] + alpha[ii] + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
if (i == len(alpha)): | |
i = 0 | |
ii += 1 | |
if (ii == len(alpha)): | |
ii = 0 | |
iii += 1 | |
skip_print += 1 | |
skip_print %= 200000 | |
if (complete == 0): | |
i = 0 | |
ii = 0 | |
iii = 0 | |
startPoint = 3 | |
# 4 character case | |
if (startPoint == 3): | |
skip_print = 0 | |
while (iiii < len(alpha)): | |
c += 1 | |
if skip_print == 0: | |
os.system('cls') | |
print "Decrypting: " + x | |
# SHA-512 | |
if (hashType == 'sha512'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha512(alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() + " (" + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha512(alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
if (i == len(alpha)): | |
i = 0 | |
ii += 1 | |
if (ii == len(alpha)): | |
ii = 0 | |
iii += 1 | |
if (iii == len(alpha)): | |
iii = 0 | |
iiii += 1 | |
# SHA256 | |
elif (hashType == 'sha256'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha256(alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() + " (" + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha256(alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
if (i == len(alpha)): | |
i = 0 | |
ii += 1 | |
if (ii == len(alpha)): | |
ii = 0 | |
iii += 1 | |
if (iii == len(alpha)): | |
iii = 0 | |
iiii += 1 | |
skip_print += 1 | |
skip_print %= 200000 | |
if (complete == 0): | |
i = 0 | |
ii = 0 | |
iii = 0 | |
iiii = 0 | |
startPoint = 4 | |
# 5 character case | |
if (startPoint == 4): | |
skip_print = 0 | |
while (iiiii < len(alpha)): | |
c += 1 | |
if skip_print == 0: | |
os.system('cls') | |
print "Decrypting: " + x | |
# SHA-512 | |
if (hashType == 'sha512'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha512(alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() + " (" + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha1(alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
if (i == len(alpha)): | |
i = 0 | |
ii += 1 | |
if (ii == len(alpha)): | |
ii = 0 | |
iii += 1 | |
if (iii == len(alpha)): | |
iii = 0 | |
iiii += 1 | |
if (iiii == len(alpha)): | |
iiii = 0 | |
iiiii += 1 | |
# SHA256 | |
elif (hashType == 'md5'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha256(alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() + " (" + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha256(alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
if (i == len(alpha)): | |
i = 0 | |
ii += 1 | |
if (ii == len(alpha)): | |
ii = 0 | |
iii += 1 | |
if (iii == len(alpha)): | |
iii = 0 | |
iiii += 1 | |
if (iiii == len(alpha)): | |
iiii = 0 | |
iiiii += 1 | |
skip_print += 1 | |
skip_print %= 200000 | |
if (complete == 0): | |
i = 0 | |
ii = 0 | |
iii = 0 | |
iiii = 0 | |
iiiii = 0 | |
startPoint = 5 | |
# 6 character case | |
if (startPoint == 5): | |
skip_print = 0 | |
while (iiiiii < len(alpha)): | |
c += 1 | |
if skip_print == 0: | |
os.system('cls') | |
print "Decrypting: " + x | |
# SHA-512 | |
if (hashType == 'sha512'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha512(alpha[iiiiii] + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() + " (" + alpha[iiiiii] + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha512(alpha[iiiiii] + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[iiiiii] + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
if (i == len(alpha)): | |
i = 0 | |
ii += 1 | |
if (ii == len(alpha)): | |
ii = 0 | |
iii += 1 | |
if (iii == len(alpha)): | |
iii = 0 | |
iiii += 1 | |
if (iiii == len(alpha)): | |
iiii = 0 | |
iiiii += 1 | |
if (iiiii == len(alpha)): | |
iiiii = 0 | |
iiiiii += 1 | |
# SHA256 | |
elif (hashType == 'sha256'): | |
if skip_print == 0: | |
print "Trying: " + hashlib.sha256(alpha[iiiiii] + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() + " (" + alpha[iiiiii] + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] + ")" | |
print "Combinations Tried: " + str(c) | |
if (hashlib.sha256(alpha[iiiiii] + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i]).hexdigest() == x): | |
print "Success! Decrypted to: " + alpha[iiiiii] + alpha[iiiii] + alpha[iiii] + alpha[iii] + alpha[ii] + alpha[i] | |
if (((time.time() - startTime) % 60) < 1): | |
print "Time Taken: Less then 1 second" | |
else: | |
print "Time Taken: " + str(int(math.floor(((time.time() - startTime) / 60) / 60))) + " hours " + str(int((math.floor((time.time() - startTime) / 60)) % 60)) + " minutes " + str(int((time.time() - startTime) % 60)) + " seconds" | |
complete = 1 | |
break | |
else: | |
i += 1 | |
if (i == len(alpha)): | |
i = 0 | |
ii += 1 | |
if (ii == len(alpha)): | |
ii = 0 | |
iii += 1 | |
if (iii == len(alpha)): | |
iii = 0 | |
iiii += 1 | |
if (iiii == len(alpha)): | |
iiii = 0 | |
iiiii += 1 | |
if (iiiii == len(alpha)): | |
iiiii = 0 | |
iiiiii += 1 | |
skip_print += 1 | |
skip_print %= 200000 | |
# User Interface and console input | |
# Get hash type and value from user, exit if invalid | |
hashType = raw_input("Hash Type?(sha512/sha256): ") | |
if (hashType != 'sha512' and hashType != 'sha256'): | |
print "Invalid input (not sha512 or sha256)" | |
os.system('pause') | |
exit(1) | |
input = raw_input("Input hash to decrypt: ") | |
# SHA-512 must be 40 characters long | |
if (len(input) != 128 and hashType == 'sha512'): | |
print "You did not enter a valid SHA-512 hash (40 characters)" | |
os.system('pause') | |
exit(1) | |
# SHA256 must be 32 characters long | |
elif (len(input) != 64 and hashType == 'sha256'): | |
print "You did not enter a valid SHA256 hash (32 characters)" | |
os.system('pause') | |
exit(1) | |
# Set up the list to use in testing | |
alpha = list('abcdefghijklmnopqrstuvwxyz') | |
# Additional tests may be added, but they greatly increase the time taken | |
input2 = raw_input("Include upper-case?(y/n): ") | |
if (input2 == 'y'): | |
alpha.extend(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']) | |
input3 = raw_input("Include numbers?(y/n): ") | |
if (input3 == 'y'): | |
alpha.extend(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']) | |
# Allow user to start from a specified string to promote parallel computing or save time | |
input4 = raw_input("Begin from a specific string?(leave blank to start from scratch): ") | |
# Decrypt and show answer with error handling | |
try: | |
decrypt(input, input4) | |
except: | |
os.system('cls') | |
print "Fatal Error!" | |
# Show error type and description | |
print str(sys.exc_type) + ":" + str(sys.exc_value) | |
os.system('pause') | |
# Protect against accidental keypresses leading to loss of data | |
print "Are you sure you want to exit?" | |
os.system('pause') | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment