mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
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>
This commit is contained in:
parent
dc07a85076
commit
15d1cfabb1
@ -448,6 +448,7 @@
|
|||||||
* [Find Min Recursion](https://github.com/TheAlgorithms/Python/blob/master/maths/find_min_recursion.py)
|
* [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)
|
* [Floor](https://github.com/TheAlgorithms/Python/blob/master/maths/floor.py)
|
||||||
* [Gamma](https://github.com/TheAlgorithms/Python/blob/master/maths/gamma.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)
|
* [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)
|
* [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)
|
* [Greedy Coin Change](https://github.com/TheAlgorithms/Python/blob/master/maths/greedy_coin_change.py)
|
||||||
|
@ -5,6 +5,7 @@ corresponding to the character's position in the alphabet.
|
|||||||
https://www.dcode.fr/letter-number-cipher
|
https://www.dcode.fr/letter-number-cipher
|
||||||
http://bestcodes.weebly.com/a1z26.html
|
http://bestcodes.weebly.com/a1z26.html
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
def encode(plain: str) -> list[int]:
|
def encode(plain: str) -> list[int]:
|
||||||
|
@ -14,6 +14,7 @@ Module includes:
|
|||||||
|
|
||||||
Created by TrapinchO
|
Created by TrapinchO
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
RotorPositionT = tuple[int, int, int]
|
RotorPositionT = tuple[int, int, int]
|
||||||
RotorSelectionT = tuple[str, str, str]
|
RotorSelectionT = tuple[str, str, str]
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# https://en.wikipedia.org/wiki/Trifid_cipher
|
# https://en.wikipedia.org/wiki/Trifid_cipher
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
def __encryptPart(messagePart: str, character2Number: dict[str, str]) -> str:
|
def __encryptPart(messagePart: str, character2Number: dict[str, str]) -> str:
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
- encrypt_file : boolean
|
- encrypt_file : boolean
|
||||||
- decrypt_file : boolean
|
- decrypt_file : boolean
|
||||||
"""
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
class XORCipher:
|
class XORCipher:
|
||||||
@ -41,17 +42,10 @@ class XORCipher:
|
|||||||
|
|
||||||
key = key or self.__key or 1
|
key = key or self.__key or 1
|
||||||
|
|
||||||
# make sure key can be any size
|
# make sure key is an appropriate size
|
||||||
while key > 255:
|
key %= 255
|
||||||
key -= 255
|
|
||||||
|
|
||||||
# This will be returned
|
return [chr(ord(ch) ^ key) for ch in content]
|
||||||
ans = []
|
|
||||||
|
|
||||||
for ch in content:
|
|
||||||
ans.append(chr(ord(ch) ^ key))
|
|
||||||
|
|
||||||
return ans
|
|
||||||
|
|
||||||
def decrypt(self, content: str, key: int) -> list[str]:
|
def decrypt(self, content: str, key: int) -> list[str]:
|
||||||
"""
|
"""
|
||||||
@ -66,17 +60,10 @@ class XORCipher:
|
|||||||
|
|
||||||
key = key or self.__key or 1
|
key = key or self.__key or 1
|
||||||
|
|
||||||
# make sure key can be any size
|
# make sure key is an appropriate size
|
||||||
while key > 255:
|
key %= 255
|
||||||
key -= 255
|
|
||||||
|
|
||||||
# This will be returned
|
return [chr(ord(ch) ^ key) for ch in content]
|
||||||
ans = []
|
|
||||||
|
|
||||||
for ch in content:
|
|
||||||
ans.append(chr(ord(ch) ^ key))
|
|
||||||
|
|
||||||
return ans
|
|
||||||
|
|
||||||
def encrypt_string(self, content: str, key: int = 0) -> str:
|
def encrypt_string(self, content: str, key: int = 0) -> str:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user