Skip to main content

A Python library for substitution cipher encryption, decryption, and cryptanalysis

Project description

📚 cipherlibUnicorn

A Python library for substitution cipher encryption, decryption, and cryptanalysis using bigram matrices and simulated annealing. Built for Czech language texts using Wikisource data.


✅ JAK TO FUNGUJE

  • download.py – stahuje data knih z Wikisource. Data nejsou přiložena v Gitu, ale mohou být vygenerována skriptem.
  • bigrams.py – práce s maticemi. Ukládají se nenormalizované, aby byly přehledné v celých číslech. transition_matrix_raw() se používá pro TM_obs, u které by umělé nahrazování nul jedničkami zhoršovalo výsledky.
  • encryption.py – šifrování, dešifrování a prolomení šifry pomocí algoritmu Metropolis-Hastings.
  • decipher_all.py – hromadné dešifrování (není součástí knihovny, ale některé funkce se mohou hodit).
  • utils.py – obsahuje konstanty jako ALPHABET a cesty ke složkám.

✅ Implementované a zdokumentované funkce požadované v zadání

  • get_bigrams(text)
  • transition_matrix(bigrams)
  • substitute_encrypt(plaintext, key)
  • substitute_decrypt(ciphertext, key)
  • prolom_substitute(text, TM_ref, iter, start_key=None)
  • plausibility(text, TM_ref)

⚙️ Parametry

  • alphabet – obsahuje abecedu písmen jako list, např. ['A', 'B', ..., '_']
  • TM_ref – referenční pravděpodobnostní matice bigramů vytvořená z normálního (nezašifrovaného) textu
  • iter – počet iterací algoritmu (doporučeno 10k – 50k)
  • start_key – volitelný uživatelem definovaný počáteční klíč; pokud není zadán, generuje se náhodně
  • text – zašifrovaný text, na kterém provádíme analýzu

🚀 Instalace

pip install cipherlibUnicorn

📓 Ukázka použití

Viz soubor notebook_demo.ipynb, kde je kompletní příklad:

  • načtení matice
  • šifrování a dešifrování
  • prolomení šifry
  • uložení výsledků

🧠 Poznámka

Projekt vznikl jako součást univerzitního zadání pro analýzu substitučních šifer. Zaměřeno na češtinu, ale lze upravit pro jiné jazyky předefinováním abecedy a referenční matice.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cipherlibunicorn-0.1.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cipherlibunicorn-0.1.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file cipherlibunicorn-0.1.1.tar.gz.

File metadata

  • Download URL: cipherlibunicorn-0.1.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for cipherlibunicorn-0.1.1.tar.gz
Algorithm Hash digest
SHA256 280b45cab5cb4811068b1790d59756ada7ad35a03bbe1cfe419db67b848f4729
MD5 b30fa931bdd90b0076fa9d13d644bd57
BLAKE2b-256 6c3001da5721d7d298e993d4a2e0bd3fd52c24c83b30e4a29866644eae93449d

See more details on using hashes here.

File details

Details for the file cipherlibunicorn-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cipherlibunicorn-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 471df100c2a6f7c6f1d734862d999b73dcdff3159e7d9319e87d64ac56042914
MD5 36d24f35459dd2080bce1426230c8b94
BLAKE2b-256 6594881e69efd62812667281aa727b0a96e033bc7c72883f51daf5a991d84ce1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page