The other day, I read the article here, and I also want to hash it and surpass the Minister's Egoza! I thought about it and studied about hashing of python. So, this time I would like to share what I learned.
-The algorithm converts the character string into a character string with invisible regularity. (Example) Before hashing: sample ↓ After hashing: b80f059f7c6301c6fb2a34615edca2634bc65fa6
-There are many types of hashing algorithms. -The character string generated by hashing is called a hash value. -It is difficult to estimate the original character string from the hash value. In other words, it is easy to convert from "original data to hash value", but it is difficult to estimate "hash value to original data". -Since it is generated by the specified algorithm, the same hash value is generated no matter how many times the same data is hashed. -If the original data changes a little, the generated hash value will be completely different. There are features such as.
hash_list.py
import hashlib
print(sorted(hashlib.algorithms_guaranteed))
#['blake2b', 'blake2s', 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'sha512', 'shake_128', 'shake_256']
print(sorted(hashlib.algorithms_available))
#['DSA', 'DSA-SHA', 'MD4', 'MD5', 'MDC2', 'RIPEMD160', 'SHA', 'SHA1', 'SHA224', 'SHA256', 'SHA384', 'SHA512', 'blake2b', 'blake2s', 'dsaEncryption', 'dsaWithSHA', 'ecdsa-with-SHA1', 'md4', 'md5', 'mdc2', 'ripemd160', 'sha', 'sha1', 'sha224', 'sha256', 'sha384', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'sha512', 'shake_128', 'shake_256', 'whirlpool']
algorithms_guaranteed: Shows "standard support" hash algorithms. algorithms_available—Displays “available” hash algorithms.
This time, I will introduce three.
hash_sample.py
import hashlib
hash_before_word = 'I do not want to work'
# MD5
hash_after_word_md5 = hashlib.md5(hash_before_word.encode()).hexdigest()
print(hash_after_word_md5)
#450ba26c03d7740818d9b0f2bb97bc5
# blake2b
hash_after_word_blake2b = hashlib.blake2b(hash_before_word.encode()).hexdigest()
print(hash_after_word_blake2b)
#52e284d94dfdc8e88c2926f234907127e98738e03e96f21a510e4822e0891385154430de8c047a4c4868199aad8b8db093d3a995952d17c738e77cab7875acf9
# sha224
hash_after_word_sha224 = hashlib.sha224(hash_before_word.encode()).hexdigest()
print(hash_after_word_sha224)
In this way, it can be hashed by multiple hash algorithms. If you want to use another hash algorithm, just change the hash algorithm name.
This time, I introduced the hashing algorithm using python. 67344549d15075a087a77f88e1ad920b21a387a9 Please use the minister's egosurfing and password management. (However, keep ethics)
No, it's ffd4a94997286e73f1031aa7464b0d0cd1213bfd.
https://docs.python.org/ja/3/library/hashlib.html
Recommended Posts