from caesar import encode, crack
geheim = encode(3, 'informatica is best wel leuk')
geheim'lqirupdwlfd lv ehvw zho ohxn'
This page demonstrates executed Python: the code blocks below actually ran when the site was rendered, and their output is baked into the page. The functions come from the caesar.py sitting next to this file.
'lqirupdwlfd lv ehvw zho ohxn'
The output above is real. And cracking it back, with nothing but letter statistics:
Letter frequencies of a Dutch paragraph, computed and plotted at render time. The code is folded away by default — click Code to unfold (the same mechanism works for model solutions).
import matplotlib.pyplot as plt
from caesar import freqs, ALPHABET
tekst = """
De leerlingen ontwerpen en implementeren algoritmen met datastructuren
voor concrete problemen. Ze passen algoritmische technieken toe bij het
programmeren van zelf ontworpen oplossingen en lossen concrete wiskundige
problemen op met behulp van numerieke methodes. Wie dit leest telt mee:
elke letter in deze zin schuift straks drie plaatsen op.
""".lower()
f = freqs(tekst)
fig, ax = plt.subplots(figsize=(8, 3.2))
ax.bar(list(ALPHABET), f, color="#4269d0", width=0.72)
ax.set_ylabel("frequentie (%)")
ax.spines[["top", "right"]].set_visible(False)
ax.grid(axis="y", alpha=0.25)
ax.set_axisbelow(True)
fig.tight_layout()
plt.show()
Vergelijk met de tabel uit het schoolreglement: ook hier is e met afstand de koploper. Hoe langer de tekst, hoe stabieler de frequenties.
Opgave. crack faalt soms. Vind een Nederlandse boodschap van minstens drie woorden waarop crack(encode(3, ...)) het verkeerde antwoord geeft.
Denk aan de mislukking uit het boek: boxing wizards jump quickly. Welke eigenschap van die zin brak de statistiek?