Skip to content

Commit

Permalink
from __future__ import annotations (TheAlgorithms#4763)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
cclauss and github-actions authored Sep 22, 2021
1 parent dc07a85 commit 15d1cfa
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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

0 comments on commit 15d1cfa

Please sign in to comment.