From c37bb9540834cb77e37822eb376a5896cda34778 Mon Sep 17 00:00:00 2001 From: Username Date: Tue, 14 Sep 2021 15:42:02 -0400 Subject: [PATCH] Fixed annotations --- ciphers/a1z26.py | 7 +++++-- ciphers/trafid_cipher.py | 11 +++++++---- ciphers/xor_cipher.py | 7 +++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index e6684fb1e..8f038a402 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -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' diff --git a/ciphers/trafid_cipher.py b/ciphers/trafid_cipher.py index 1c8ea3024..f4bf45b3d 100644 --- a/ciphers/trafid_cipher.py +++ b/ciphers/trafid_cipher.py @@ -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() diff --git a/ciphers/xor_cipher.py b/ciphers/xor_cipher.py index 12d580e72..6bd22ea24 100644 --- a/ciphers/xor_cipher.py +++ b/ciphers/xor_cipher.py @@ -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