如何在Python中创建独立于平台的GUID?我听说有一种方法在Windows上使用ActivePython,但它只是Windows,因为它使用COM.有没有使用普通Python的方法?
我有这个错误:
Traceback (most recent call last):
File "python_md5_cracker.py", line 27, in <module>
m.update(line)
TypeError: Unicode-objects must be encoded before hashing
Run Code Online (Sandbox Code Playgroud)
当我尝试在Python 3.2.2中执行此代码时:
import hashlib, sys
m = hashlib.md5()
hash = ""
hash_file = input("What is the file name in which the hash resides? ")
wordlist = input("What is your wordlist? (Enter the file name) ")
try:
hashdocument = open(hash_file, "r")
except IOError:
print("Invalid file.")
raw_input()
sys.exit()
else:
hash = hashdocument.readline()
hash = hash.replace("\n", "")
try:
wordlistfile = open(wordlist, …Run Code Online (Sandbox Code Playgroud) 我需要生成可以在文件名中使用的唯一标识符,并且可以在给定相同的输入值的情况下进行复制。我需要生成数百万个这样的标识符,因为源输入有数百万种组合。
为简单起见,我将在示例中使用一个小的集合,但实际的集合可能会相当大(数百,也许数千个项目);大于可以手动编码为文件名。
我注意到生成 UUID 的第 5 种方法允许您提供字符串输入。
> input_set = {'apple', 'banana', 'orange'}
> uuid.uuid5(uuid.NAMESPACE_URL, pickle.dumps(input_set)).hex
'f39926529ad45997984643816c1bc403'
Run Code Online (Sandbox Code Playgroud)
文档说它SHA1在幕后使用。碰撞风险是否太高?有没有更好的方法来可靠地散列唯一标识符?