【python】sha256

Pythonのハッシュ値を求める関数はhashlibにある

import hashlib

x = 'abc'

m = hashlib.md5(x.encode()).hexdigest()
sha256 = hashlib.sha256(x.encode()).hexdigest()
sha384 = hashlib.sha384(x.encode()).hexdigest()
sha512 = hashlib.sha512(x.encode()).hexdigest()


print(m)
print(sha256)
print(sha384)
print(sha512)

encodeはコードの符号化
hexdigest は16進数文字列に変換

$ python3 test.py
900150983cd24fb0d6963f7d28e17f72
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7
ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f