From f47d87aa0181565a5efe23c78cfbda7b93e68a04 Mon Sep 17 00:00:00 2001 From: Erwin Junge Date: Sat, 23 Oct 2021 21:16:34 +0200 Subject: [PATCH 1/3] [mypy] annotate `ciphers` --- ciphers/decrypt_caesar_with_chi_squared.py | 11 +++++++---- ciphers/polybius.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ciphers/decrypt_caesar_with_chi_squared.py b/ciphers/decrypt_caesar_with_chi_squared.py index 89477914a030..beac851b6c2a 100644 --- a/ciphers/decrypt_caesar_with_chi_squared.py +++ b/ciphers/decrypt_caesar_with_chi_squared.py @@ -221,10 +221,13 @@ def decrypt_caesar_with_chi_squared( # Get the most likely cipher by finding the cipher with the smallest chi squared # statistic - most_likely_cipher: int = min( # type: ignore - chi_squared_statistic_values, # type: ignore - key=chi_squared_statistic_values.get, # type: ignore - ) # type: ignore + def chi_squared_statistic_values_sorting_key(key: int) -> tuple[float, str]: + return chi_squared_statistic_values[key] + + most_likely_cipher: int = min( + chi_squared_statistic_values, + key=chi_squared_statistic_values_sorting_key, + ) # Get all the data from the most likely cipher (key, decoded message) ( diff --git a/ciphers/polybius.py b/ciphers/polybius.py index 9e1dc4cbb5a8..b0ca05153bdb 100644 --- a/ciphers/polybius.py +++ b/ciphers/polybius.py @@ -45,7 +45,7 @@ def numbers_to_letter(self, index1: int, index2: int) -> str: >>> PolybiusCipher().numbers_to_letter(1, 1) == "a" True """ - letter = self.SQUARE[index1 - 1, index2 - 1] + letter: str = self.SQUARE[index1 - 1, index2 - 1] return letter def encode(self, message: str) -> str: From 329f4c58520c329550a85e82ce1dcfc87843f190 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 26 Oct 2021 12:30:39 +0200 Subject: [PATCH 2/3] Update ciphers/polybius.py --- ciphers/polybius.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ciphers/polybius.py b/ciphers/polybius.py index b0ca05153bdb..bdcbe64c0f91 100644 --- a/ciphers/polybius.py +++ b/ciphers/polybius.py @@ -45,7 +45,7 @@ def numbers_to_letter(self, index1: int, index2: int) -> str: >>> PolybiusCipher().numbers_to_letter(1, 1) == "a" True """ - letter: str = self.SQUARE[index1 - 1, index2 - 1] + return self.SQUARE[index1 - 1, index2 - 1] return letter def encode(self, message: str) -> str: From ba315b19a419447af43b1845a4180330839045d8 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 26 Oct 2021 12:31:22 +0200 Subject: [PATCH 3/3] Update polybius.py --- ciphers/polybius.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ciphers/polybius.py b/ciphers/polybius.py index bdcbe64c0f91..2a45f02a3773 100644 --- a/ciphers/polybius.py +++ b/ciphers/polybius.py @@ -46,7 +46,6 @@ def numbers_to_letter(self, index1: int, index2: int) -> str: True """ return self.SQUARE[index1 - 1, index2 - 1] - return letter def encode(self, message: str) -> str: """