-
-
Notifications
You must be signed in to change notification settings - Fork 47.3k
Educational Implementation of the SHA-256 Hash Function #12887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
import sys | ||
|
||
|
||
def ripemd160(b: bytes) -> bytes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: b
self.buffer: list[int] = [0] * 64 | ||
|
||
|
||
def update(ctx, inp, inplen): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: update
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: ctx
Please provide type hint for the parameter: inp
Please provide type hint for the parameter: inplen
ctx.buffer[have + i] = inp[off + i] | ||
|
||
|
||
def final(ctx): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: final
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: ctx
PADDING = [0x80] + [0] * 63 | ||
|
||
|
||
def rol(n, x): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: rol
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: n
Please provide descriptive name for the parameter: n
Please provide type hint for the parameter: x
Please provide descriptive name for the parameter: x
return ((x << n) & 0xFFFFFFFF) | (x >> (32 - n)) | ||
|
||
|
||
def f0(x, y, z): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: f0
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: x
Please provide descriptive name for the parameter: x
Please provide type hint for the parameter: y
Please provide descriptive name for the parameter: y
Please provide type hint for the parameter: z
Please provide descriptive name for the parameter: z
return ((x & y) ^ (x & z) ^ (y & z)) & MASK32 | ||
|
||
|
||
def b2i(b: bytes) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: b
return int.from_bytes(b, byteorder="big") | ||
|
||
|
||
def i2b(i: int) -> bytes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: i
# ============================================================================= | ||
|
||
|
||
def is_prime(n: int) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: n
return all(n % f != 0 for f in range(2, math.isqrt(n) + 1)) | ||
|
||
|
||
def first_n_primes(n: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: first_n_primes
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: n
return islice(filter(is_prime, count(start=2)), n) | ||
|
||
|
||
def frac_bin(f: float, n: int = 32) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide descriptive name for the parameter: f
Please provide descriptive name for the parameter: n
Description
Educational SHA-256 implementation in Python with type hints and doctests.
References
-https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
Checklist