Skip to content

Commit 06e1eb7

Browse files
authored
Add files via upload
1 parent 5b0249a commit 06e1eb7

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

ciphers/a1z26.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
"""
88

99

10-
from typing import List
10+
# from typing import List
11+
from __future__ import annotations
1112

1213

13-
def encode(plain: str) -> List[int]:
14+
def encode(plain: str) -> list[int]:
1415
"""
1516
>>> encode("myname")
1617
[13, 25, 14, 1, 13, 5]
1718
"""
1819
return [ord(elem) - 96 for elem in plain]
1920

2021

21-
def decode(encoded: List[int]) -> str:
22+
def decode(encoded: list[int]) -> str:
2223
"""
2324
>>> decode([13, 25, 14, 1, 13, 5])
2425
'myname'

ciphers/enigma_machine2.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
1515
Created by TrapinchO
1616
"""
17-
from typing import Dict, Tuple
17+
from __future__ import annotations
18+
19+
from typing import Tuple
1820

1921
RotorPositionT = Tuple[int, int, int]
2022
RotorSelectionT = Tuple[str, str, str]
@@ -70,7 +72,7 @@
7072

7173
def _validator(
7274
rotpos: RotorPositionT, rotsel: RotorSelectionT, pb: str
73-
) -> Tuple[RotorPositionT, RotorSelectionT, Dict[str, str]]:
75+
) -> tuple[RotorPositionT, RotorSelectionT, dict[str, str]]:
7476
"""
7577
Checks if the values can be used for the 'enigma' function
7678
@@ -111,7 +113,7 @@ def _validator(
111113
return rotpos, rotsel, pbdict
112114

113115

114-
def _plugboard(pbstring: str) -> Dict[str, str]:
116+
def _plugboard(pbstring: str) -> dict[str, str]:
115117
"""
116118
https://en.wikipedia.org/wiki/Enigma_machine#Plugboard
117119

ciphers/trafid_cipher.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# https://en.wikipedia.org/wiki/Trifid_cipher
22

33

4-
from typing import Dict, Tuple
4+
from __future__ import annotations
55

66

7-
def __encryptPart(messagePart: str, character2Number: Dict[str, str]) -> str:
7+
def __encryptPart(messagePart: str, character2Number: dict[str, str]) -> str:
88
one, two, three = "", "", ""
99
tmp = []
1010

@@ -20,8 +20,8 @@ def __encryptPart(messagePart: str, character2Number: Dict[str, str]) -> str:
2020

2121

2222
def __decryptPart(
23-
messagePart: str, character2Number: Dict[str, str]
24-
) -> Tuple[str, str, str]:
23+
messagePart: str, character2Number: dict[str, str]
24+
) -> tuple[str, str, str]:
2525
tmp, thisPart = "", ""
2626
result = []
2727

@@ -39,7 +39,7 @@ def __decryptPart(
3939

4040
def __prepare(
4141
message: str, alphabet: str
42-
) -> Tuple[str, str, Dict[str, str], Dict[str, str]]:
42+
) -> tuple[str, str, dict[str, str], dict[str, str]]:
4343
# Validate message and alphabet, set to upper and remove spaces
4444
alphabet = alphabet.replace(" ", "").upper()
4545
message = message.replace(" ", "").upper()

ciphers/xor_cipher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"""
1919

2020

21-
from typing import List
21+
from __future__ import annotations
2222

2323

2424
class XORCipher:
@@ -31,7 +31,7 @@ def __init__(self, key: int = 0):
3131
# private field
3232
self.__key = key
3333

34-
def encrypt(self, content: str, key: int) -> List[str]:
34+
def encrypt(self, content: str, key: int) -> list[str]:
3535
"""
3636
input: 'content' of type string and 'key' of type int
3737
output: encrypted string 'content' as a list of chars
@@ -56,7 +56,7 @@ def encrypt(self, content: str, key: int) -> List[str]:
5656

5757
return ans
5858

59-
def decrypt(self, content: str, key: int) -> List[str]:
59+
def decrypt(self, content: str, key: int) -> list[str]:
6060
"""
6161
input: 'content' of type list and 'key' of type int
6262
output: decrypted string 'content' as a list of chars

0 commit comments

Comments
 (0)