How to encrypt all possible strings in a defined character set python?

前端 未结 4 704

I am trying to encrypt all possible strings in a defined character set then compare them to a hash given by user input.

This is what I currently have

imp         


        
4条回答
  •  有刺的猬
    2021-01-26 15:09

    Here's my completely different answer based on J.F. Sebastian's answer and comment about my previous answer. The most important point being that crypt.METHOD_CRYPT is not a callable even though the documentation somewhat confusingly calls a hashing method as if it were a method function of a module or an instance. It's not -- just think of it as an id or name of one of the various kinds of encryption supported by the crypt module.

    So the problem with you code is two-fold: One is that you were trying to use wordchars as a string, when it actually a tuple produced by product() and second, that you're trying to call the id crypt.METHOD_CRYPT.

    I'm at a bit of a disadvantage answering this because I'm not running Unix, don't have Python v3.3 installed, and don't completely understand what you're trying to accomplish with your code. Given all those caveats, I think something like the following which is derived from you code ought to at least run:

    import string
    from itertools import product
    import crypt
    
    def decrypt():
        hash1 = input("Please enter the hash: ")
        salt = input("Please enter the salt: ")
        charSet = string.ascii_letters + string.digits
        for wordchars in product(charSet, repeat=2):
            hash2 = crypt.crypt(''.join(wordchars), salt=salt)  # or salt=crypt.METHOD_CRYPT
            print(hash2)
    

提交回复
热议问题