write-ups-challenges-2024-2025/royal-message-decryptor/generator.py
2024-11-25 22:32:28 +01:00

83 lines
3.7 KiB
Python

import random
import string
import signal
messages = [
"Advance the knights from the east; let the banners be visible to all.",
"Charge the cavalry across the plains with speed—make the ground tremble beneath them.",
"Send a column of soldiers from the forest, shields raised, weapons at the ready.",
"Deploy scouts to the riverbank; observe their defenses without being seen.",
"Line the battlements with archers, and have the infantry gather at the forest's edge.",
"Send a detachment of riders to flank the hillside and strike their rear.",
"Move the siege engines forward; prepare them to target the castle walls.",
"March the battalion of spearmen down the valley road in perfect formation.",
"Halt the army at the mountain's base; wait for the reinforcements to arrive.",
"Under the cover of night, move the foot soldiers through the forest toward the west gate.",
"Break the cavalry formation, spread across the plains, and encircle them.",
"Cross the river with the infantry, shields up, and press toward their defenses.",
"Advance the siege towers slowly; let them loom over the field as a show of power.",
"Begin constructing palisades outside the village; block the main road leading to the castle.",
"Set up camp near the bridge; have the engineers secure the crossing by dusk.",
"Split the forces: one group toward the northern gate, the other to secure the southern ridge.",
"Raise the banners on the hill; archers prepare to volley, infantry ready behind them.",
"Withdraw the scouts after they encounter the patrol; signal the main force to advance.",
"Position the catapults under cover of darkness; infantry hold a defensive line until ready.",
"Send raiders to attack the supply convoy near the western pass—cut off their resources.",
"Begin scaling the cliffs with infantry to bypass the watchtower guarding the southern approach.",
"Set up camp on the plains just beyond the river; prepare for a dawn assault.",
"Advance the pikemen in a solid wall through the valley; have the archers provide cover from the ridges.",
"Reinforcements from the north, join the main army in the valley—prepare for a combined assault.",
"Divide the army into three columns: one toward the eastern gate, another through the southern forest, and a third to secure the ridge for a coordinated dawn attack.",
"Our smartest wizards have found the secret to eternal life, it is not 42, but rather IGCTF{Some-wicked-story-unfolded-here-great-work}.",
]
letters = [c for c in string.ascii_letters]
def generate_substitution():
l = letters[:]
random.shuffle(l)
return l
def kill():
print(
"*You get violently decapitated while a crowd of desensitized dirty towns people watch the show with their family*"
)
exit(0)
def generate_and_solve(msg):
sub = generate_substitution()
search_map = dict(zip(letters, sub))
new_msg = "".join([search_map[c] if c in search_map else c for c in msg])
print(f"{''.join(sub)} | {new_msg}")
inp = input("What does it say!!!> ")
if inp != msg:
print("YOU IDIOT! That was wrong. We lost troops because of you!")
kill()
print("Ok, it seemed to be right, the king is pleased")
def took_too_long(_, __):
print("YOU IDIOT! You took too long. We lost troops because of you!")
kill()
def main():
print(
"Help! We intercepted messages from the enemy, if you do not decipher them quickly our royal highness will have you decapitated!"
)
signal.signal(signal.SIGALRM, took_too_long)
signal.alarm(10)
for msg in messages:
generate_and_solve(msg)
print("You did great, no decapitations today!")
if __name__ == "__main__":
main()