hashes.sha256¶
Implementation of SHA256 Hash function in a Python class and provides utilities to find hash of string or hash of text from a file.
- Usage: python sha256.py –string “Hello World!!”
python sha256.py –file “hello_world.txt” When run without any arguments, it prints the hash of the string “Hello World!! Welcome to Cryptography”
References: https://qvault.io/cryptography/how-sha-2-works-step-by-step-sha-256/ https://en.wikipedia.org/wiki/SHA-2
Classes¶
Class to contain the entire pipeline for SHA1 Hashing Algorithm |
|
Test class for the SHA256 class. Inherits the TestCase class from unittest |
Functions¶
|
Provides option 'string' or 'file' to take input |
Module Contents¶
- class hashes.sha256.SHA256(data: bytes)¶
Class to contain the entire pipeline for SHA1 Hashing Algorithm
>>> SHA256(b'Python').hash '18885f27b5af9012df19e496460f9294d5ab76128824c6f993787004f6d9a7db'
>>> SHA256(b'hello world').hash 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
- final_hash() None ¶
- static preprocessing(data: bytes) bytes ¶
- ror(value: int, rotations: int) int ¶
Right rotate a given unsigned number by a certain amount of rotations
- data¶
- hashes = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]¶
- preprocessed_data¶
- round_constants = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221,...¶
- class hashes.sha256.SHA256HashTest(methodName='runTest')¶
Bases:
unittest.TestCase
Test class for the SHA256 class. Inherits the TestCase class from unittest
- test_match_hashes() None ¶
- hashes.sha256.main() None ¶
Provides option ‘string’ or ‘file’ to take input and prints the calculated SHA-256 hash