python - 为什么我在使用 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")
解决方案
您的语法错误来自自己调用 encode() 。您需要预先添加一个字符串来调用该函数。"your_string".encode()
这应该可以解决您的语法错误,并希望能回答您的问题。
推荐阅读
- javascript - 查找字符串中的最大数 [jquery]
- python - 将 1 xn 数组提高到 mx 1 数组中的所有幂到 Python 中的 mxn 数组
- python - 来自所有行python的相同字符串
- python - 生成永远不会停止的随机数,除非用户停止它 numpy
- python - 如何为类型参数设置 python 类型
- android - 带有 mp3 资源的 Kotlin 计划通知
- reactjs - React Typescript - 在路由中传递时如何将类型添加到 location.state
- css - 在悬停时显示组件框,如下拉菜单和弹出窗口
- ruby-on-rails-5 - 在 Rails 5 中,如何在成员字段上编写查找器“like”查询?
- flutter - 如何在 Flutter 应用程序的 initState 期间使用来自 Provider 的数据