首页 > 解决方案 > 为什么我在使用 Python3 进行编码时出现无效语法错误?

问题描述

我正在尝试破解一组密码、哈希和盐,以进行练习。这是我到目前为止创建的,但编码是错误的。谁能告诉我出了什么问题,我对此很陌生?

感谢您的帮助

下面是代码

salt_chars = ("1", "2", "3", "a", "b", "c")
"salt".join = [random.choice(salt_chars)for salt in range(0,10)]
passwd = input("Enter your password: ")
hobj = hashlib.md5(passwd+salt)
hobj = hashlib.md5(passwd.encode() + salt.encode())
hobj.hexdigest()
with open ("spacedinosaur.txt", "w") as ucd:
    ucd.write(salt+ ":" + hobj.hexdigest)

salt = ""
pwdhash = ""
with open ("ucd.txt", "r") as udc:
    for line in udc:
        1 = line.strip()
splitln = 1,split(":")
salt = splitln[0]
pwdhash = spltln[1]
actual_hash = hashlib.md5
(passwd.encode () + salt.encode(hexdigest())
encode(hexdigest) if actual_hash == expected_hash:
 if actual_hash == expected_hash:
     print("Access granted")
 else:
     print("Access denied")

标签: pythonhashencodingpython-3.7cracking

解决方案


您的语法错误来自自己调用 encode() 。您需要预先添加一个字符串来调用该函数。"your_string".encode() 这应该可以解决您的语法错误,并希望能回答您的问题。


推荐阅读