diff --git a/DIRECTORY.md b/DIRECTORY.md index 0c00d5ca7f70..eba63e17eaff 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -449,6 +449,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 e6684fb1e6fc..0f0eb7c5c083 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -5,6 +5,7 @@ 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 f4ce5a075f46..9252dd0edbf7 100644 --- a/ciphers/enigma_machine2.py +++ b/ciphers/enigma_machine2.py @@ -14,6 +14,7 @@ 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 1c8ea3024d33..b12ceff72907 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 12d580e720bc..ca9dfe20f7b6 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 @@ def encrypt(self, content: str, key: int) -> list[str]: key = key or self.__key or 1 - # make sure key can be any size - while key > 255: - key -= 255 - - # This will be returned - ans = [] - - for ch in content: - ans.append(chr(ord(ch) ^ key)) + # make sure key is an appropriate size + key %= 255 - return ans + return [chr(ord(ch) ^ key) for ch in content] def decrypt(self, content: str, key: int) -> list[str]: """ @@ -66,17 +60,10 @@ def decrypt(self, content: str, key: int) -> list[str]: key = key or self.__key or 1 - # make sure key can be any size - while key > 255: - key -= 255 - - # This will be returned - ans = [] - - for ch in content: - ans.append(chr(ord(ch) ^ key)) + # make sure key is an appropriate size + key %= 255 - return ans + return [chr(ord(ch) ^ key) for ch in content] def encrypt_string(self, content: str, key: int = 0) -> str: """