Trying Again - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Trying Again (/thread-2632.html) |
Trying Again - Able98 - Mar-30-2017 Now that I installed Windows 7 pro and Python 2.7.13 I am trying to get it running. Newer "better" version found here: https://github.com/danielchalef/pyethrecoverv3 This is my first snag:
RE: Trying Again - metulburr - Mar-30-2017 Have you tried googling? One of the first results shows http://stackoverflow.com/questions/1710922/how-to-install-pkg-config-in-windows Have you tried these? RE: Trying Again - Able98 - Apr-01-2017 If I understand correctly, out of the lib I am trying to install or import, I only need one function - "decode_keystore_json". So, I just copied it and placed it in my code and commented out the import request. Now python does not ask for the import anymore but the program does two things - It is asking for a global variable "counter" and it hangs up where I can not end it's task with the windows task manager and I have to restart the computer. Please review the following code. #!/usr/bin/python #from keys import decode_keystore_json #keys.py from pyethereum, #we only want the decode_keystore_json function import json import itertools import sys import traceback from joblib import Parallel, delayed import multiprocessing wordlist = "words3.txt" with open(wordlist) as f: dictlist = f.read().splitlines() w = { "address": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "crypto": { "cipher": "aes-128-ctr", "ciphertext": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "cipherparams": { "iv": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, "kdf": "scrypt", "kdfparams": { "dklen": 32, "n": 262144, "p": 1, "r": 8, "salt": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, "mac": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" }, "id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "version": 3 } # Constructing passwords from possible combinations (see doc of pyethrecover) grammar=[ ('abe ', 'dan ', 'mary '), ('lincoln ', 'jesus ', 'johnson '), dictlist # we append the wordlist. This isn't necessary if you think you've included all possible words above ] # print(grammar) def generate_all(el, tr): #taken from pyethrecover if el: for j in xrange(len(el[0])): for w in generate_all(el[1:], tr + el[0][j]): # print(w) yield w else: yield tr def attempt(w, pw): # print(pw) # sys.stdout.write("\r") # sys.stdout.write("\rAttempt #%d: %s" % (counter.value, pw)) #prints simple progress with # in list that is tested and the pw string sys.stdout.write("Attempt #%d: %s\n" % (counter.value, pw)) #prints simple progress with # in list that is tested and the pw string sys.stdout.flush() #print(counter.value) counter.increment() if len(pw) < 10: return "" try: o = decode_keystore_json(w,pw) print(o) # print (pw)q raise PasswordFoundException( """\n\nYour password is:\n%s""" % o) except ValueError as e: # print(e) return "" class Counter(object): def __init__(self): self.val = multiprocessing.Value('i', 0) def increment(self, n=1): with self.val.get_lock(): self.val.value += n @property def value(self): return self.val.value #------------------------- def decode_keystore_json(jsondata, pw): # Get KDF function and parameters if "crypto" in jsondata: cryptdata = jsondata["crypto"] elif "Crypto" in jsondata: cryptdata = jsondata["Crypto"] else: raise Exception("JSON data must contain \"crypto\" object") kdfparams = cryptdata["kdfparams"] kdf = cryptdata["kdf"] if cryptdata["kdf"] not in kdfs: raise Exception("Hash algo %s not supported" % kdf) kdfeval = kdfs[kdf]["calc"] # Get cipher and parameters cipherparams = cryptdata["cipherparams"] cipher = cryptdata["cipher"] if cryptdata["cipher"] not in ciphers: raise Exception("Encryption algo %s not supported" % cipher) decrypt = ciphers[cipher]["decrypt"] # Compute the derived key derivedkey = kdfeval(pw, kdfparams) assert len(derivedkey) >= 32, \ "Derived key must be at least 32 bytes long" # print(b'derivedkey: ' + encode_hex(derivedkey)) enckey = derivedkey[:16] # print(b'enckey: ' + encode_hex(enckey)) ctext = decode_hex(cryptdata["ciphertext"]) # Decrypt the ciphertext # print(ctext, enckey, cipherparams) o = decrypt(ctext, enckey, cipherparams) # Compare the provided MAC with a locally computed MAC # print(b'macdata: ' + encode_hex(derivedkey[16:32] + ctext)) mac1 = sha3(derivedkey[16:32] + ctext) mac2 = decode_hex(cryptdata["mac"]) if mac1 != mac2: raise ValueError("MAC mismatch. Password incorrect?") return o #---------------------------- def __main__(): global counter counter = Counter() pwds = [] pwds = itertools.chain(pwds, generate_all(grammar,'')) # n_pws = len(list(pwds)) # print 'Number of passwords to test: %d' % (n_pws) try: Parallel(n_jobs=-1)(delayed(attempt)(w, pw) for pw in pwds) # print("\n") except Exception, e: traceback.print_exc() while True: sys.stdout.write('\a') sys.stdout.flush() if __name__ == "__main__": __main__() |