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):
|
||||
def __init__(self):
|
||||
self.secret = "TAJENKA"
|
||||
self.user_phrase = None
|
||||
|
||||
def get_name(self):
|
||||
return "TAJENKA DELENIM"
|
||||
@ -13,21 +13,20 @@ class DivisionCipherJob(Job):
|
||||
def configure(self):
|
||||
print("\n--- Configure Division Cipher ---")
|
||||
phrase = input("Enter secret phrase (default: Random): ").strip().upper()
|
||||
|
||||
raw_secret = phrase if phrase else random.choice(CZECH_WORDS)
|
||||
|
||||
self.user_phrase = phrase if phrase else None
|
||||
|
||||
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
|
||||
nfkd_form = unicodedata.normalize('NFKD', raw_secret)
|
||||
only_ascii = "".join([c for c in nfkd_form if not unicodedata.combining(c)])
|
||||
|
||||
# Keep only A-Z
|
||||
self.secret = "".join([c for c in only_ascii.upper() if 'A' <= c <= 'Z'])
|
||||
|
||||
if not self.secret:
|
||||
self.secret = "TAJENKA"
|
||||
|
||||
def print_body(self, p):
|
||||
secret = self.secret
|
||||
# Keep only A-Z
|
||||
secret = "".join([c for c in only_ascii.upper() if 'A' <= c <= 'Z'])
|
||||
|
||||
if not secret:
|
||||
secret = "TAJENKA"
|
||||
|
||||
p.text("Vylusti tajenku!\n")
|
||||
p.text("Vysledek deleni je poradi pismena\n")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user