Advertisement
hiallaah

Untitled

Jan 17th, 2022
517
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import hashlib
  2.  
  3. ### THIS FUNCTION WILL NOT HELP YOU FIND THE FLAG --LT ########################
  4. def str_xor(secret, key):
  5.     #extend key to secret length
  6.     new_key = key
  7.     i = 0
  8.     while len(new_key) < len(secret):
  9.         new_key = new_key + key[i]
  10.         i = (i + 1) % len(key)        
  11.     return "".join([chr(ord(secret_c) ^ ord(new_key_c)) for (secret_c,new_key_c) in zip(secret,new_key)])
  12. ###############################################################################
  13.  
  14. flag_enc = open('level5.flag.txt.enc', 'rb').read()
  15. correct_pw_hash = open('level5.hash.bin', 'rb').read()
  16.  
  17. def hash_pw(pw_str):
  18.     pw_bytes = bytearray()
  19.     pw_bytes.extend(pw_str.encode())
  20.     m = hashlib.md5()
  21.     m.update(pw_bytes)
  22.     return m.digest()
  23.  
  24.  
  25. def level_5_pw_check():
  26.     user_pw_hash = hash_pw(user_pw)
  27.    
  28.     if( user_pw_hash == correct_pw_hash ):
  29.         print("Welcome back... your flag, user:")
  30.         decryption = str_xor(flag_enc.decode(), user_pw)
  31.         print(decryption)
  32.         return
  33.     print("That password is incorrect")
  34.  
  35.  
  36.  
  37. with open('dictionary.txt','r') as f:
  38.     for line in f:
  39.         for word in line.split():
  40.             user_pw = word
  41.             print(word)
  42.             level_5_pw_check()
  43.  
  44.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement