import hashlib
import os
def get_sha1(f):
xd = open('D:/1.zip', 'rb').read()
gys = xd
os.remove('D:/1.zip')
sha1 = hashlib.sha1(gys)
osv = sha1.hexdigest()
print(osv)
bx = bytes(osv, encoding='utf-8')
with open('D:/1.abc', 'wb') as f:
f.write(bx)
def get_sha2(f):
xd = open('D:/1.abc', 'rb').read()
gys = xd
os.remove('D:/1.abc')
sha2 = hashlib.sha1(gys)
osv = sha2.hexdigest()
print(osv)
bx = bytes(osv, encoding='utf-8')
with open('D:/1.zip', 'wb') as f:
f.write(bx)
get_sha2('')
这段代码是使用hashlib库中的sha1算法对文件"D:/1.zip"进行哈希,并将哈希值转化为字符串并写入文件"D:/1.abc"。然后对文件"D:/1.abc"进行哈希操作,并将哈希值转化为字符串并写入文件"D:/1.zip"。由于哈希是不可逆的,所以无法使用这段代码解密文件。