Skip to content

Instantly share code, notes, and snippets.

@AlexLynd
Last active September 24, 2021 13:14
Show Gist options
  • Save AlexLynd/4503d855bf26f7f2ef41b071e36f0768 to your computer and use it in GitHub Desktop.
Save AlexLynd/4503d855bf26f7f2ef41b071e36f0768 to your computer and use it in GitHub Desktop.
Python basic hash cracker / encoder [GCI 2019-20]
import hashlib, sys
def get_hash(case, arg) :
hash_val = {
1: hashlib.md5(arg.encode('utf-8')).hexdigest() ,
2: hashlib.sha1(arg.encode('utf-8')).hexdigest() ,
3: hashlib.sha224(arg.encode('utf-8')).hexdigest() ,
4: hashlib.sha256(arg.encode('utf-8')).hexdigest() ,
5: hashlib.sha384(arg.encode('utf-8')).hexdigest() ,
6: hashlib.sha512(arg.encode('utf-8')).hexdigest() ,
}
return (hash_val.get(case,"Invalid"))
def crack(hash_val, wordlist):
wlist = open(wordlist, "r", encoding= "utf-8")
for line in wlist:
for word in line.split():
for i in range(1,7):
if (get_hash(int(i), str(word)) == hash_val):
return(word)
return "hash not found."
while True:
print("1. Hasher \n2. Hash Cracker \n3. quit")
select = int(input("Choice: "))
if select == 1:
print("\n1. md5 \n2. sha1 \n3. sha224 \n4. sha256 \n5. sha384 \n6. sha512")
hashtype, text = input('Hash type: '), input('Text to hash: ')
print(get_hash(int(hashtype), str(text))+"\n-------------------------------")
elif select == 2:
file, hash_crack = input("Word list: "), input("Hash to crack: ")
print("Hash found: "+crack(str(hash_crack),str(file))+"\n-------------------------------")
else:
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment