#9: Implementing Stromchiffre

- Also various bug fixes and improvements
This commit is contained in:
2021-10-22 17:35:22 +02:00
parent 97d833349c
commit 087a01cd3d
3 changed files with 128 additions and 8 deletions
+18 -3
View File
@@ -1,8 +1,10 @@
import decimal
LETTERS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z']
def is_letter_of_alphabet(letter: str):
def is_letter_of_alphabet(letter: str) -> bool:
"""
Checks if the given letter is a valid letter of the alphabet
:param letter: The letter to check
@@ -11,7 +13,7 @@ def is_letter_of_alphabet(letter: str):
return letter.upper() in LETTERS
def get_letter_at_index(idx: int, capital: bool = False):
def get_letter_at_index(idx: int, capital: bool = False) -> str:
"""
Returns the letter at the given index
:param idx: The index of the letter to return
@@ -24,7 +26,7 @@ def get_letter_at_index(idx: int, capital: bool = False):
return LETTERS[idx] if capital else LETTERS[idx].lower()
def get_index_of_letter(letter: str):
def get_index_of_letter(letter: str) -> int:
"""
Returns the index of the given letter
:param letter: The letter to return the index of
@@ -34,3 +36,16 @@ def get_index_of_letter(letter: str):
raise AttributeError
return LETTERS.index(letter.upper())
def get_binary_index_of_letter(letter: str) -> str:
"""
Returns the binary representation of the letter index
:param letter: The letter to return the index for
:return: The binary representation of the letter index
"""
char_index = get_index_of_letter(letter)
return bin(char_index)[2:].zfill(6)
def get_letter_at_binary_index(index: str) -> str:
decimal_index = int(index, 2)
return get_letter_at_index(decimal_index)