两个字符串相等,但python说它们是n

2024-05-15 21:23:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的代码,它有助于强制哈希 第一个if语句将运行,值是hash=wordlist.txtargs=abtfgvalues=[0, "0,1", 0, wordlist.txt, true]

def bruteforce(hash, args, values):
    if "." in hash:
        files = open(values[args.find("f")]) # Open wordlist.txt
        for xhsd in files.readlines():
            hash = xhsd
            alphabet = "abcdefghijklmnopqrstuvwxyz"
            alphabet += alphabet.upper() + "0123456789!$%^&*(){}~#][;:'@/?.>,<"
            if "b" in args: # It is
                m = args.find("b")
                m = values[m]
            else:
                m = "0,16"
            # m is 0,10
            start_time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
            l = 0
            print("Cracking...")
            attempts = 0
            while l == 0:
                password = ""
                for x in range(random.randrange(int(m.split(",")[0])+1,int(m.split(",")[1])+1)): # range(random.randrange(0,10))
                    password += alphabet[random.randrange(0,len(alphabet)-1)]
                num = hash_types[int(values[args.find("t")])] # num="md5"
                htype = "hash2 = hashlib."+num+"(password).hexdigest()"
                exec(htype) # hash2 = md5(password)
                print hash2 + ":" + hash # Compares the hashes
                if hash == hash2:
                    print password
                    l = 1
                else:
                    print "Trying..."

它尝试的第一件东西,几乎立刻就裂开了,打印:

0cc175b9c0f1b6a831c399e269772661:0cc175b9c0f1b6a831c399e269772661

(这是hash2和hash)。所以我们现在知道这两个变量是相等的。但是,它下面的if语句不会运行。这是我在Python中看到的最奇怪的事情,有人能解释为什么会这样吗?我打印了两个变量,它们显然是一样的。。。你知道吗


Tags: intxtifargsrandompasswordhashfind