为什么这不起作用的任何想法?我真的认为'忽略'会做正确的事.
>>> 'add \x93Monitoring\x93 to list '.encode('latin-1','ignore')
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0x93 in position 4: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud) 这是Python 3中的代码,它使用salt生成密码:
import hmac
import random
import string
import hashlib
def make_salt():
salt = ""
for i in range(5):
salt = salt + random.choice(string.ascii_letters)
return salt
def make_pw_hash(pw, salt = None):
if (salt == None):
salt = make_salt() #.encode('utf-8') - not working either
return hashlib.sha256(pw + salt).hexdigest()+","+ salt
pw = make_pw_hash('123')
print(pw)
Run Code Online (Sandbox Code Playgroud)
它给我的错误是:
Traceback (most recent call last):
File "C:\Users\german\test.py", line 20, in <module>
pw = make_pw_hash('123')
File "C:\Users\german\test.py", line 17, in make_pw_hash
return hashlib.sha256(pw + salt).hexdigest()+","+ …Run Code Online (Sandbox Code Playgroud) 我想读一个密码文件.然后我尝试计算每个密码的哈希值,并将其与我已经拥有的哈希值进行比较,以确定我是否发现了密码.但是我不断得到的错误消息是"TypeError:必须在散列之前对Unicode对象进行编码".这是我的代码:
from hashlib import sha256
with open('words','r') as f:
for line in f:
hashedWord = sha256(line.rstrip()).hexdigest()
if hashedWord == 'ca52258a43795ab5c89513f9984b8f3d3d0aa61fb7792ecefe8d90010ee39f2':
print(line + "is one of the words!")
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙并提供解释吗?
我正在努力integer为stringPython 生成给定类型的ID 。
我认为内置hash功能是完美的,但有时ID似乎太长。这是一个问题,因为最大长度限制为64位。
到目前为止,我的代码:hash(s) % 10000000000。我可以预期的输入字符串的长度将在12-512个字符之间。
要求是:
如果有人可以提供任何提示/解决方案,我将非常高兴。
我试图从文件中哈希密码,然后将其与用户给出的密码进行匹配。并不是超级安全,只是足够安全,以便密码在文件中不是纯文本。我收到错误
TypeError: Unicode-objects must be encoded before hashing
Run Code Online (Sandbox Code Playgroud)
如果我输入 hashpass = hashlib.md5(b'p').hexdigest() 它会起作用,但它只加密“p”
我如何让它加密我的字符串输入?
程序
import hashlib
status = ""
def passhash():
code = open("password.txt", "r")
password = code.readline()
global encrypt
encrypt = hashlib.md5(password).hexdigest()
def checkPassword():
for key in range(3):
p = input("Enter the password >>")
hashpass = hashlib.md5(p).hexdigest()
if hashpass == encrypt:
print("password correct!")
status = "q"
return status
else:
print ('wrong password, try again')
print ('you have failed')
def Main():
status = input("p for program, q to quit: …Run Code Online (Sandbox Code Playgroud)