Created
January 2, 2020 04:53
-
-
Save nanpuyue/60e857c78d15d9f5c7e47b1e6c844fbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# date: 2019-01-02 | |
# license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt | |
# author: nanpuyue <[email protected]> https://blog.nanpuyue.com | |
def sha2_iv(n: int) -> int: | |
square_root = pow(n, 1/2) | |
decimal = square_root - int(square_root) | |
return int(decimal * 0x100000000) | |
def sha2_it(n: int) -> int: | |
cube_root = pow(n, 1/3) | |
decimal = cube_root - int(cube_root) | |
return int(decimal * 0x100000000) | |
def is_prime_number(n: int, pn_list: list) -> bool: | |
for pn in pn_list: | |
if n % pn == 0: | |
return False | |
return True | |
def for_prime_number_do(count: int, f): | |
i = 0 | |
n = 2 | |
prime_number_list = [] | |
while i < count: | |
if is_prime_number(n, prime_number_list): | |
prime_number_list.append(n) | |
i += 1 | |
print("0x%08x" % f(n), end=", ") | |
if i % 8 == 0: | |
print() | |
n += 1 | |
print("Initialize variables:") | |
for_prime_number_do(8, sha2_iv) | |
print("\nInitialize table:") | |
for_prime_number_do(64, sha2_it) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output