Fixed annotations

This commit is contained in:
Username 2021-09-14 15:42:02 -04:00
parent e3678fdead
commit c37bb95408
3 changed files with 17 additions and 8 deletions

View File

@ -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") >>> encode("myname")
[13, 25, 14, 1, 13, 5] [13, 25, 14, 1, 13, 5]
@ -15,7 +18,7 @@ def encode(plain: str) -> list[int]:
return [ord(elem) - 96 for elem in plain] 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]) >>> decode([13, 25, 14, 1, 13, 5])
'myname' 'myname'

View File

@ -1,7 +1,10 @@
# https://en.wikipedia.org/wiki/Trifid_cipher # 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 = "", "", "" one, two, three = "", "", ""
tmp = [] tmp = []
@ -17,8 +20,8 @@ def __encryptPart(messagePart: str, character2Number: dict[str, str]) -> str:
def __decryptPart( def __decryptPart(
messagePart: str, character2Number: dict[str, str] messagePart: str, character2Number: Dict[str, str]
) -> tuple[str, str, str]: ) -> Tuple[str, str, str]:
tmp, thisPart = "", "" tmp, thisPart = "", ""
result = [] result = []
@ -36,7 +39,7 @@ def __decryptPart(
def __prepare( def __prepare(
message: str, alphabet: str 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 # Validate message and alphabet, set to upper and remove spaces
alphabet = alphabet.replace(" ", "").upper() alphabet = alphabet.replace(" ", "").upper()
message = message.replace(" ", "").upper() message = message.replace(" ", "").upper()

View File

@ -18,6 +18,9 @@
""" """
from typing import List
class XORCipher: class XORCipher:
def __init__(self, key: int = 0): def __init__(self, key: int = 0):
""" """
@ -28,7 +31,7 @@ class XORCipher:
# private field # private field
self.__key = key 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 input: 'content' of type string and 'key' of type int
output: encrypted string 'content' as a list of chars output: encrypted string 'content' as a list of chars
@ -53,7 +56,7 @@ class XORCipher:
return ans 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 input: 'content' of type list and 'key' of type int
output: decrypted string 'content' as a list of chars output: decrypted string 'content' as a list of chars