From 15d1cfabb15903c5e9d4d103e2390876efb3f85f Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 22 Sep 2021 23:11:51 +0200 Subject: [PATCH] from __future__ import annotations (#4763) * from __future__ import annotations * updating DIRECTORY.md * from __future__ import annotations * from __future__ import annotations * Update xor_cipher.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> --- DIRECTORY.md | 1 + ciphers/a1z26.py | 1 + ciphers/enigma_machine2.py | 1 + ciphers/trafid_cipher.py | 1 + ciphers/xor_cipher.py | 27 +++++++-------------------- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 0d44e10ad..2e9942b5b 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -448,6 +448,7 @@ * [Find Min Recursion](https://github.com/TheAlgorithms/Python/blob/master/maths/find_min_recursion.py) * [Floor](https://github.com/TheAlgorithms/Python/blob/master/maths/floor.py) * [Gamma](https://github.com/TheAlgorithms/Python/blob/master/maths/gamma.py) + * [Gamma Recursive](https://github.com/TheAlgorithms/Python/blob/master/maths/gamma_recursive.py) * [Gaussian](https://github.com/TheAlgorithms/Python/blob/master/maths/gaussian.py) * [Greatest Common Divisor](https://github.com/TheAlgorithms/Python/blob/master/maths/greatest_common_divisor.py) * [Greedy Coin Change](https://github.com/TheAlgorithms/Python/blob/master/maths/greedy_coin_change.py) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index e6684fb1e..0f0eb7c5c 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -5,6 +5,7 @@ corresponding to the character's position in the alphabet. https://www.dcode.fr/letter-number-cipher http://bestcodes.weebly.com/a1z26.html """ +from __future__ import annotations def encode(plain: str) -> list[int]: diff --git a/ciphers/enigma_machine2.py b/ciphers/enigma_machine2.py index f4ce5a075..9252dd0ed 100644 --- a/ciphers/enigma_machine2.py +++ b/ciphers/enigma_machine2.py @@ -14,6 +14,7 @@ Module includes: Created by TrapinchO """ +from __future__ import annotations RotorPositionT = tuple[int, int, int] RotorSelectionT = tuple[str, str, str] diff --git a/ciphers/trafid_cipher.py b/ciphers/trafid_cipher.py index 1c8ea3024..b12ceff72 100644 --- a/ciphers/trafid_cipher.py +++ b/ciphers/trafid_cipher.py @@ -1,4 +1,5 @@ # https://en.wikipedia.org/wiki/Trifid_cipher +from __future__ import annotations def __encryptPart(messagePart: str, character2Number: dict[str, str]) -> str: diff --git a/ciphers/xor_cipher.py b/ciphers/xor_cipher.py index 12d580e72..ca9dfe20f 100644 --- a/ciphers/xor_cipher.py +++ b/ciphers/xor_cipher.py @@ -16,6 +16,7 @@ - encrypt_file : boolean - decrypt_file : boolean """ +from __future__ import annotations class XORCipher: @@ -41,17 +42,10 @@ class XORCipher: key = key or self.__key or 1 - # make sure key can be any size - while key > 255: - key -= 255 + # make sure key is an appropriate size + key %= 255 - # This will be returned - ans = [] - - for ch in content: - ans.append(chr(ord(ch) ^ key)) - - return ans + return [chr(ord(ch) ^ key) for ch in content] def decrypt(self, content: str, key: int) -> list[str]: """ @@ -66,17 +60,10 @@ class XORCipher: key = key or self.__key or 1 - # make sure key can be any size - while key > 255: - key -= 255 + # make sure key is an appropriate size + key %= 255 - # This will be returned - ans = [] - - for ch in content: - ans.append(chr(ord(ch) ^ key)) - - return ans + return [chr(ord(ch) ^ key) for ch in content] def encrypt_string(self, content: str, key: int = 0) -> str: """