Division cipher: Fix secret being the same
This commit is contained in:
parent
6d16d40b7f
commit
b9e96b5945
@ -5,7 +5,7 @@ from jobs.czech_words import CZECH_WORDS
|
|||||||
|
|
||||||
class DivisionCipherJob(Job):
|
class DivisionCipherJob(Job):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.secret = "TAJENKA"
|
self.user_phrase = None
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return "TAJENKA DELENIM"
|
return "TAJENKA DELENIM"
|
||||||
@ -13,21 +13,20 @@ class DivisionCipherJob(Job):
|
|||||||
def configure(self):
|
def configure(self):
|
||||||
print("\n--- Configure Division Cipher ---")
|
print("\n--- Configure Division Cipher ---")
|
||||||
phrase = input("Enter secret phrase (default: Random): ").strip().upper()
|
phrase = input("Enter secret phrase (default: Random): ").strip().upper()
|
||||||
|
self.user_phrase = phrase if phrase else None
|
||||||
|
|
||||||
raw_secret = phrase if phrase else random.choice(CZECH_WORDS)
|
def print_body(self, p):
|
||||||
|
raw_secret = self.user_phrase if self.user_phrase else random.choice(CZECH_WORDS)
|
||||||
|
|
||||||
# Remove accents to ensure mapping to A-Z works
|
# Remove accents to ensure mapping to A-Z works
|
||||||
nfkd_form = unicodedata.normalize('NFKD', raw_secret)
|
nfkd_form = unicodedata.normalize('NFKD', raw_secret)
|
||||||
only_ascii = "".join([c for c in nfkd_form if not unicodedata.combining(c)])
|
only_ascii = "".join([c for c in nfkd_form if not unicodedata.combining(c)])
|
||||||
|
|
||||||
# Keep only A-Z
|
# Keep only A-Z
|
||||||
self.secret = "".join([c for c in only_ascii.upper() if 'A' <= c <= 'Z'])
|
secret = "".join([c for c in only_ascii.upper() if 'A' <= c <= 'Z'])
|
||||||
|
|
||||||
if not self.secret:
|
if not secret:
|
||||||
self.secret = "TAJENKA"
|
secret = "TAJENKA"
|
||||||
|
|
||||||
def print_body(self, p):
|
|
||||||
secret = self.secret
|
|
||||||
|
|
||||||
p.text("Vylusti tajenku!\n")
|
p.text("Vylusti tajenku!\n")
|
||||||
p.text("Vysledek deleni je poradi pismena\n")
|
p.text("Vysledek deleni je poradi pismena\n")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user