Skip to content

Commit 700398e

Browse files
ErwinJungecclauss
andauthored
[mypy] annotate ciphers (TheAlgorithms#5569)
* [mypy] annotate `ciphers` * Update ciphers/polybius.py * Update polybius.py Co-authored-by: Christian Clauss <[email protected]>
1 parent e49d8e3 commit 700398e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

ciphers/decrypt_caesar_with_chi_squared.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,13 @@ def decrypt_caesar_with_chi_squared(
221221

222222
# Get the most likely cipher by finding the cipher with the smallest chi squared
223223
# statistic
224-
most_likely_cipher: int = min( # type: ignore
225-
chi_squared_statistic_values, # type: ignore
226-
key=chi_squared_statistic_values.get, # type: ignore
227-
) # type: ignore
224+
def chi_squared_statistic_values_sorting_key(key: int) -> tuple[float, str]:
225+
return chi_squared_statistic_values[key]
226+
227+
most_likely_cipher: int = min(
228+
chi_squared_statistic_values,
229+
key=chi_squared_statistic_values_sorting_key,
230+
)
228231

229232
# Get all the data from the most likely cipher (key, decoded message)
230233
(

ciphers/polybius.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ def numbers_to_letter(self, index1: int, index2: int) -> str:
4545
>>> PolybiusCipher().numbers_to_letter(1, 1) == "a"
4646
True
4747
"""
48-
letter = self.SQUARE[index1 - 1, index2 - 1]
49-
return letter
48+
return self.SQUARE[index1 - 1, index2 - 1]
5049

5150
def encode(self, message: str) -> str:
5251
"""

0 commit comments

Comments
 (0)