mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Fixed annotations
This commit is contained in:
parent
e3678fdead
commit
c37bb95408
|
@ -7,7 +7,10 @@ http://bestcodes.weebly.com/a1z26.html
|
|||
"""
|
||||
|
||||
|
||||
def encode(plain: str) -> list[int]:
|
||||
from typing import List
|
||||
|
||||
|
||||
def encode(plain: str) -> List[int]:
|
||||
"""
|
||||
>>> encode("myname")
|
||||
[13, 25, 14, 1, 13, 5]
|
||||
|
@ -15,7 +18,7 @@ def encode(plain: str) -> list[int]:
|
|||
return [ord(elem) - 96 for elem in plain]
|
||||
|
||||
|
||||
def decode(encoded: list[int]) -> str:
|
||||
def decode(encoded: List[int]) -> str:
|
||||
"""
|
||||
>>> decode([13, 25, 14, 1, 13, 5])
|
||||
'myname'
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
# https://en.wikipedia.org/wiki/Trifid_cipher
|
||||
|
||||
|
||||
def __encryptPart(messagePart: str, character2Number: dict[str, str]) -> str:
|
||||
from typing import Tuple, Dict
|
||||
|
||||
|
||||
def __encryptPart(messagePart: str, character2Number: Dict[str, str]) -> str:
|
||||
one, two, three = "", "", ""
|
||||
tmp = []
|
||||
|
||||
|
@ -17,8 +20,8 @@ def __encryptPart(messagePart: str, character2Number: dict[str, str]) -> str:
|
|||
|
||||
|
||||
def __decryptPart(
|
||||
messagePart: str, character2Number: dict[str, str]
|
||||
) -> tuple[str, str, str]:
|
||||
messagePart: str, character2Number: Dict[str, str]
|
||||
) -> Tuple[str, str, str]:
|
||||
tmp, thisPart = "", ""
|
||||
result = []
|
||||
|
||||
|
@ -36,7 +39,7 @@ def __decryptPart(
|
|||
|
||||
def __prepare(
|
||||
message: str, alphabet: str
|
||||
) -> tuple[str, str, dict[str, str], dict[str, str]]:
|
||||
) -> Tuple[str, str, Dict[str, str], Dict[str, str]]:
|
||||
# Validate message and alphabet, set to upper and remove spaces
|
||||
alphabet = alphabet.replace(" ", "").upper()
|
||||
message = message.replace(" ", "").upper()
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
"""
|
||||
|
||||
|
||||
from typing import List
|
||||
|
||||
|
||||
class XORCipher:
|
||||
def __init__(self, key: int = 0):
|
||||
"""
|
||||
|
@ -28,7 +31,7 @@ class XORCipher:
|
|||
# private field
|
||||
self.__key = key
|
||||
|
||||
def encrypt(self, content: str, key: int) -> list[str]:
|
||||
def encrypt(self, content: str, key: int) -> List[str]:
|
||||
"""
|
||||
input: 'content' of type string and 'key' of type int
|
||||
output: encrypted string 'content' as a list of chars
|
||||
|
@ -53,7 +56,7 @@ class XORCipher:
|
|||
|
||||
return ans
|
||||
|
||||
def decrypt(self, content: str, key: int) -> list[str]:
|
||||
def decrypt(self, content: str, key: int) -> List[str]:
|
||||
"""
|
||||
input: 'content' of type list and 'key' of type int
|
||||
output: decrypted string 'content' as a list of chars
|
||||
|
|
Loading…
Reference in New Issue
Block a user