From 08e80f6ebd91a8a8b733461476c06b426f4aa6a4 Mon Sep 17 00:00:00 2001 From: algobytewise Date: Fri, 2 Apr 2021 14:24:21 +0530 Subject: [PATCH 1/6] fix hashes-folder --- hashes/adler32.py | 2 +- hashes/chaos_machine.py | 3 ++- hashes/enigma_machine.py | 7 +++---- hashes/sdbm.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hashes/adler32.py b/hashes/adler32.py index fad747abe3c3..370c20c07868 100644 --- a/hashes/adler32.py +++ b/hashes/adler32.py @@ -26,4 +26,4 @@ def adler32(plain_text: str) -> str: for plain_chr in plain_text: a = (a + ord(plain_chr)) % MOD_ADLER b = (b + a) % MOD_ADLER - return (b << 16) | a + return str((b << 16) | a) diff --git a/hashes/chaos_machine.py b/hashes/chaos_machine.py index 1bdf984b68de..5cedc6d50502 100644 --- a/hashes/chaos_machine.py +++ b/hashes/chaos_machine.py @@ -6,7 +6,8 @@ m = 5 # Buffer Space (with Parameters Space) -buffer_space, params_space = [], [] +buffer_space: list = [] +params_space: list = [] # Machine Time machine_time = 0 diff --git a/hashes/enigma_machine.py b/hashes/enigma_machine.py index 5420bacc1409..d1cb6efc2e8d 100644 --- a/hashes/enigma_machine.py +++ b/hashes/enigma_machine.py @@ -41,8 +41,7 @@ def engine(input_character): if __name__ == "__main__": - decode = input("Type your message:\n") - decode = list(decode) + decode = list(input("Type your message:\n")) while True: try: token = int(input("Please set token:(must be only digits)\n")) @@ -51,8 +50,8 @@ def engine(input_character): print(error) for i in range(token): rotator() - for i in decode: - engine(i) + for j in decode: + engine(j) print("\n" + "".join(code)) print( f"\nYour Token is {token} please write it down.\nIf you want to decode " diff --git a/hashes/sdbm.py b/hashes/sdbm.py index 86d47a1d9967..9e2a96286345 100644 --- a/hashes/sdbm.py +++ b/hashes/sdbm.py @@ -34,4 +34,4 @@ def sdbm(plain_text: str) -> str: hash = 0 for plain_chr in plain_text: hash = ord(plain_chr) + (hash << 6) + (hash << 16) - hash - return hash + return str(hash) From 60ae1e79a413311aead3d600380f2ce86dce9b8a Mon Sep 17 00:00:00 2001 From: algobytewise Date: Fri, 2 Apr 2021 14:24:49 +0530 Subject: [PATCH 2/6] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e66b94b1a074..c1aeaa031565 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: python -m pip install mypy pytest-cov -r requirements.txt # FIXME: #4052 fix mypy errors in the exclude directories and remove them below - run: mypy --ignore-missing-imports - --exclude '(ciphers|conversions|data_structures|digital_image_processing|dynamic_programming|graphs|hashes|linear_algebra|maths|matrix|other|project_euler|scripts|searches|strings*)/$' . + --exclude '(ciphers|conversions|data_structures|digital_image_processing|dynamic_programming|graphs|linear_algebra|maths|matrix|other|project_euler|scripts|searches|strings*)/$' . - name: Run tests run: pytest --doctest-modules --ignore=project_euler/ --ignore=scripts/ --cov-report=term-missing:skip-covered --cov=. . - if: ${{ success() }} From e0049947ee3d649784348266eab4615bf572eb96 Mon Sep 17 00:00:00 2001 From: algobytewise Date: Fri, 2 Apr 2021 14:47:41 +0530 Subject: [PATCH 3/6] fix doctests --- hashes/adler32.py | 4 ++-- hashes/sdbm.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hashes/adler32.py b/hashes/adler32.py index 370c20c07868..422e44deb4cb 100644 --- a/hashes/adler32.py +++ b/hashes/adler32.py @@ -15,10 +15,10 @@ def adler32(plain_text: str) -> str: Itterates and evaluates new value for each character >>> adler32('Algorithms') - 363791387 + '363791387' >>> adler32('go adler em all') - 708642122 + '708642122' """ MOD_ADLER = 65521 a = 1 diff --git a/hashes/sdbm.py b/hashes/sdbm.py index 9e2a96286345..ed31008aecb2 100644 --- a/hashes/sdbm.py +++ b/hashes/sdbm.py @@ -26,10 +26,10 @@ def sdbm(plain_text: str) -> str: them. >>> sdbm('Algorithms') - 1462174910723540325254304520539387479031000036 + '1462174910723540325254304520539387479031000036' >>> sdbm('scramble bits') - 730247649148944819640658295400555317318720608290373040936089 + '730247649148944819640658295400555317318720608290373040936089' """ hash = 0 for plain_chr in plain_text: From 24e146c83d9c6b3f00f815ff14bf3877d9c6d987 Mon Sep 17 00:00:00 2001 From: algobytewise Date: Fri, 2 Apr 2021 16:57:09 +0530 Subject: [PATCH 4/6] return-values to int --- hashes/adler32.py | 10 +++++----- hashes/sdbm.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hashes/adler32.py b/hashes/adler32.py index 422e44deb4cb..2b9cbc32f7ef 100644 --- a/hashes/adler32.py +++ b/hashes/adler32.py @@ -9,16 +9,16 @@ """ -def adler32(plain_text: str) -> str: +def adler32(plain_text: str) -> int: """ Function implements adler-32 hash. - Itterates and evaluates new value for each character + Itterates and evaluates a new value for each character >>> adler32('Algorithms') - '363791387' + 363791387 >>> adler32('go adler em all') - '708642122' + 708642122 """ MOD_ADLER = 65521 a = 1 @@ -26,4 +26,4 @@ def adler32(plain_text: str) -> str: for plain_chr in plain_text: a = (a + ord(plain_chr)) % MOD_ADLER b = (b + a) % MOD_ADLER - return str((b << 16) | a) + return (b << 16) | a diff --git a/hashes/sdbm.py b/hashes/sdbm.py index ed31008aecb2..daf292717f75 100644 --- a/hashes/sdbm.py +++ b/hashes/sdbm.py @@ -19,19 +19,19 @@ """ -def sdbm(plain_text: str) -> str: +def sdbm(plain_text: str) -> int: """ Function implements sdbm hash, easy to use, great for bits scrambling. iterates over each character in the given string and applies function to each of them. >>> sdbm('Algorithms') - '1462174910723540325254304520539387479031000036' + 1462174910723540325254304520539387479031000036 >>> sdbm('scramble bits') - '730247649148944819640658295400555317318720608290373040936089' + 730247649148944819640658295400555317318720608290373040936089 """ hash = 0 for plain_chr in plain_text: hash = ord(plain_chr) + (hash << 6) + (hash << 16) - hash - return str(hash) + return hash From ba8395cf2340e09f8ddbae746f2e547880ce0053 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 2 Apr 2021 14:02:37 +0200 Subject: [PATCH 5/6] Update hashes/adler32.py --- hashes/adler32.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashes/adler32.py b/hashes/adler32.py index 2b9cbc32f7ef..4a61b97e3590 100644 --- a/hashes/adler32.py +++ b/hashes/adler32.py @@ -12,7 +12,7 @@ def adler32(plain_text: str) -> int: """ Function implements adler-32 hash. - Itterates and evaluates a new value for each character + Iterates and evaluates a new value for each character >>> adler32('Algorithms') 363791387 From 17a4804ad99a0cb23242254cda5134f68df2d188 Mon Sep 17 00:00:00 2001 From: algobytewise Date: Sat, 3 Apr 2021 09:58:46 +0530 Subject: [PATCH 6/6] type hints for elements --- hashes/chaos_machine.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hashes/chaos_machine.py b/hashes/chaos_machine.py index 5cedc6d50502..7ef4fdb3ca51 100644 --- a/hashes/chaos_machine.py +++ b/hashes/chaos_machine.py @@ -6,8 +6,8 @@ m = 5 # Buffer Space (with Parameters Space) -buffer_space: list = [] -params_space: list = [] +buffer_space: list[float] = [] +params_space: list[float] = [] # Machine Time machine_time = 0