Division cipher: make the cipher configurable

This commit is contained in:
Dejvino 2025-12-23 23:54:24 +01:00
parent 510ea220cc
commit 4575584b9d
2 changed files with 33 additions and 9 deletions

View File

@ -1,13 +1,33 @@
import random import random
import unicodedata
from .base import Job from .base import Job
from jobs.czech_words import CZECH_WORDS
class DivisionCipherJob(Job): class DivisionCipherJob(Job):
def __init__(self):
self.secret = "TAJENKA"
def get_name(self): def get_name(self):
return "TAJENKA (DELENI)" return "TAJENKA DELENIM"
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)
# 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): def print_body(self, p):
words = ["TONIK", "ROBOT", "MOBIL", "MAMISEK", "SLADKE", "BOBEK", "BOREC", "HUSTY", "VOLNO", "HOTOVE"] secret = self.secret
secret = random.choice(words)
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")

View File

@ -16,17 +16,21 @@ class WordSearchJob:
def configure(self): def configure(self):
print("\n--- Configure Word Search ---") print("\n--- Configure Word Search ---")
phrase = input("Enter hidden phrase (default: TAJENKA): ").strip().upper() phrase = input("Enter hidden phrase (default: Random): ").strip().upper()
if phrase: if phrase:
self.hidden_phrase = "".join(c for c in phrase if c.isalnum()) self.hidden_phrase = "".join(c for c in phrase if c.isalnum())
else: else:
self.hidden_phrase = "TAJENKA" self.hidden_phrase = random.choice(CZECH_WORDS)
self.width = len(self.hidden_phrase) + 2 self.width = len(self.hidden_phrase) + 2
self.height = len(self.hidden_phrase) + 2 self.height = len(self.hidden_phrase) + 2
size = int(input(f"Enter size (default: {self.width}): ").strip()) size_str = input(f"Enter size (default: {self.width}): ").strip()
if size: if size_str:
try:
size = int(size_str)
self.width = size self.width = size
self.height = size self.height = size
except ValueError:
pass
if self.width < 5: if self.width < 5:
self.width = 5 self.width = 5
self.height = 5 self.height = 5