Skip to content

Commit 15d1cfa

Browse files
cclaussgithub-actions
and
github-actions
authored
from __future__ import annotations (TheAlgorithms#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>
1 parent dc07a85 commit 15d1cfa

File tree

5 files changed

+11
-20
lines changed

5 files changed

+11
-20
lines changed

Diff for: DIRECTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@
448448
* [Find Min Recursion](https://github.com/TheAlgorithms/Python/blob/master/maths/find_min_recursion.py)
449449
* [Floor](https://github.com/TheAlgorithms/Python/blob/master/maths/floor.py)
450450
* [Gamma](https://github.com/TheAlgorithms/Python/blob/master/maths/gamma.py)
451+
* [Gamma Recursive](https://github.com/TheAlgorithms/Python/blob/master/maths/gamma_recursive.py)
451452
* [Gaussian](https://github.com/TheAlgorithms/Python/blob/master/maths/gaussian.py)
452453
* [Greatest Common Divisor](https://github.com/TheAlgorithms/Python/blob/master/maths/greatest_common_divisor.py)
453454
* [Greedy Coin Change](https://github.com/TheAlgorithms/Python/blob/master/maths/greedy_coin_change.py)

Diff for: ciphers/a1z26.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
https://www.dcode.fr/letter-number-cipher
66
http://bestcodes.weebly.com/a1z26.html
77
"""
8+
from __future__ import annotations
89

910

1011
def encode(plain: str) -> list[int]:

Diff for: ciphers/enigma_machine2.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1515
Created by TrapinchO
1616
"""
17+
from __future__ import annotations
1718

1819
RotorPositionT = tuple[int, int, int]
1920
RotorSelectionT = tuple[str, str, str]

Diff for: ciphers/trafid_cipher.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# https://en.wikipedia.org/wiki/Trifid_cipher
2+
from __future__ import annotations
23

34

45
def __encryptPart(messagePart: str, character2Number: dict[str, str]) -> str:

Diff for: ciphers/xor_cipher.py

+7-20
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- encrypt_file : boolean
1717
- decrypt_file : boolean
1818
"""
19+
from __future__ import annotations
1920

2021

2122
class XORCipher:
@@ -41,17 +42,10 @@ def encrypt(self, content: str, key: int) -> list[str]:
4142

4243
key = key or self.__key or 1
4344

44-
# make sure key can be any size
45-
while key > 255:
46-
key -= 255
47-
48-
# This will be returned
49-
ans = []
50-
51-
for ch in content:
52-
ans.append(chr(ord(ch) ^ key))
45+
# make sure key is an appropriate size
46+
key %= 255
5347

54-
return ans
48+
return [chr(ord(ch) ^ key) for ch in content]
5549

5650
def decrypt(self, content: str, key: int) -> list[str]:
5751
"""
@@ -66,17 +60,10 @@ def decrypt(self, content: str, key: int) -> list[str]:
6660

6761
key = key or self.__key or 1
6862

69-
# make sure key can be any size
70-
while key > 255:
71-
key -= 255
72-
73-
# This will be returned
74-
ans = []
75-
76-
for ch in content:
77-
ans.append(chr(ord(ch) ^ key))
63+
# make sure key is an appropriate size
64+
key %= 255
7865

79-
return ans
66+
return [chr(ord(ch) ^ key) for ch in content]
8067

8168
def encrypt_string(self, content: str, key: int = 0) -> str:
8269
"""

0 commit comments

Comments
 (0)