From 700398ec063687b661e9be865f5c32d3c822fca1 Mon Sep 17 00:00:00 2001 From: Erwin Junge Date: Tue, 26 Oct 2021 12:35:21 +0200 Subject: [PATCH] [mypy] annotate `ciphers` (#5569) * [mypy] annotate `ciphers` * Update ciphers/polybius.py * Update polybius.py Co-authored-by: Christian Clauss --- ciphers/decrypt_caesar_with_chi_squared.py | 11 +++++++---- ciphers/polybius.py | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ciphers/decrypt_caesar_with_chi_squared.py b/ciphers/decrypt_caesar_with_chi_squared.py index 89477914a..beac851b6 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 9e1dc4cbb..2a45f02a3 100644 --- a/ciphers/polybius.py +++ b/ciphers/polybius.py @@ -45,8 +45,7 @@ class PolybiusCipher: >>> PolybiusCipher().numbers_to_letter(1, 1) == "a" True """ - letter = self.SQUARE[index1 - 1, index2 - 1] - return letter + return self.SQUARE[index1 - 1, index2 - 1] def encode(self, message: str) -> str: """