mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-07 19:46:30 +08:00
refactor: Move constants outside of variable scope (#7262)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
@ -9,16 +9,17 @@ https://www.braingle.com/brainteasers/codes/bifid.php
|
||||
|
||||
import numpy as np
|
||||
|
||||
SQUARE = [
|
||||
["a", "b", "c", "d", "e"],
|
||||
["f", "g", "h", "i", "k"],
|
||||
["l", "m", "n", "o", "p"],
|
||||
["q", "r", "s", "t", "u"],
|
||||
["v", "w", "x", "y", "z"],
|
||||
]
|
||||
|
||||
|
||||
class BifidCipher:
|
||||
def __init__(self) -> None:
|
||||
SQUARE = [ # noqa: N806
|
||||
["a", "b", "c", "d", "e"],
|
||||
["f", "g", "h", "i", "k"],
|
||||
["l", "m", "n", "o", "p"],
|
||||
["q", "r", "s", "t", "u"],
|
||||
["v", "w", "x", "y", "z"],
|
||||
]
|
||||
self.SQUARE = np.array(SQUARE)
|
||||
|
||||
def letter_to_numbers(self, letter: str) -> np.ndarray:
|
||||
|
@ -1,3 +1,6 @@
|
||||
import string
|
||||
|
||||
|
||||
def decrypt(message: str) -> None:
|
||||
"""
|
||||
>>> decrypt('TMDETUX PMDVU')
|
||||
@ -28,16 +31,15 @@ def decrypt(message: str) -> None:
|
||||
Decryption using Key #24: VOFGVWZ ROFXW
|
||||
Decryption using Key #25: UNEFUVY QNEWV
|
||||
"""
|
||||
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" # noqa: N806
|
||||
for key in range(len(LETTERS)):
|
||||
for key in range(len(string.ascii_uppercase)):
|
||||
translated = ""
|
||||
for symbol in message:
|
||||
if symbol in LETTERS:
|
||||
num = LETTERS.find(symbol)
|
||||
if symbol in string.ascii_uppercase:
|
||||
num = string.ascii_uppercase.find(symbol)
|
||||
num = num - key
|
||||
if num < 0:
|
||||
num = num + len(LETTERS)
|
||||
translated = translated + LETTERS[num]
|
||||
num = num + len(string.ascii_uppercase)
|
||||
translated = translated + string.ascii_uppercase[num]
|
||||
else:
|
||||
translated = translated + symbol
|
||||
print(f"Decryption using Key #{key}: {translated}")
|
||||
|
@ -8,16 +8,18 @@ https://www.braingle.com/brainteasers/codes/polybius.php
|
||||
|
||||
import numpy as np
|
||||
|
||||
SQUARE = [
|
||||
["a", "b", "c", "d", "e"],
|
||||
["f", "g", "h", "i", "k"],
|
||||
["l", "m", "n", "o", "p"],
|
||||
["q", "r", "s", "t", "u"],
|
||||
["v", "w", "x", "y", "z"],
|
||||
]
|
||||
|
||||
|
||||
class PolybiusCipher:
|
||||
def __init__(self) -> None:
|
||||
SQUARE = [ # noqa: N806
|
||||
["a", "b", "c", "d", "e"],
|
||||
["f", "g", "h", "i", "k"],
|
||||
["l", "m", "n", "o", "p"],
|
||||
["q", "r", "s", "t", "u"],
|
||||
["v", "w", "x", "y", "z"],
|
||||
]
|
||||
|
||||
self.SQUARE = np.array(SQUARE)
|
||||
|
||||
def letter_to_numbers(self, letter: str) -> np.ndarray:
|
||||
|
Reference in New Issue
Block a user