Problem with argument substitution in function

1

I have a problem with the arguments that I pass in the function below, I am trying to pass the sha512 argument to hash_type , so that in the code within the function the substitution, and so the hash_target would be passed by the correct hash algorithm, however whenever I run the code, python returns an error message saying that the hashlib library has no function hash_type , which shows that the replacement is not happening, what can be done to fix this problem?

Code:

import sys
import hashlib


def main(hash_type,wordlist='palavrasptbr'):
    hash_target = input("Hash :\n")
    hash_target = bytes(hash_target.encode('utf-8'))
    wordlist += '.txt'
    archive = open(wordlist, 'r')
    print(archive)

    hash_target = bytes(hash_target)

    print(hashing_sha512(bytes(hash_target)))

def hashing_sha512(hash_target):
    hashing = hashlib.sha512()
    hashing.update(hash_target)
    return hashing.hexdigest()


if __name__ == "__main__":
    try:
        main(sys.argv[1], sys.argv[2])
    except KeyboardInterrupt:
        pass
    
asked by anonymous 07.09.2017 / 04:17

1 answer

0

First: Your code does not work without modifications. It is not a good way to ask for help.

  • In its function main the argument hash_type is not used.
  • You upload the file to archive = open(wordlist, 'r') but you do not use it.
  • Try a different approach:

  • Make your argv [1] a string that maps you a function:

    if argv[1] == 'sha512':
        hashfunc = hashlib.sha512
    
  • 05.12.2017 / 12:56