Skip to content

from __future__ import annotations #4763

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

Merged
merged 5 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ciphers/a1z26.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
1 change: 1 addition & 0 deletions ciphers/enigma_machine2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

Created by TrapinchO
"""
from __future__ import annotations

RotorPositionT = tuple[int, int, int]
RotorSelectionT = tuple[str, str, str]
Expand Down
1 change: 1 addition & 0 deletions ciphers/trafid_cipher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# https://en.wikipedia.org/wiki/Trifid_cipher
from __future__ import annotations


def __encryptPart(messagePart: str, character2Number: dict[str, str]) -> str:
Expand Down
27 changes: 7 additions & 20 deletions ciphers/xor_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- encrypt_file : boolean
- decrypt_file : boolean
"""
from __future__ import annotations


class XORCipher:
Expand All @@ -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]:
"""
Expand All @@ -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:
"""
Expand Down