Write a python program that prints its own sha256 hash
时间: 2024-05-29 18:08:42 浏览: 120
SHA256Hash值生成工具
4星 · 用户满意度95%
Sure, here's the code:
import hashlib
with open(__file__, 'r') as f:
file_contents = f.read().encode('utf-8') # Read in the file as a bytes object
hash_object = hashlib.sha256(file_contents) # Generate the sha256 hash
print(hash_object.hexdigest()) # Print the hash in hexadecimal format
Please note that this code will only work if you run it from a file, not if you run it in a REPL or interpreter. Also, if you modify the file in any way, the hash will be different.
阅读全文