Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

AI Cipher Decoder

An AI-powered tool for encrypting, decrypting, and auto-cracking classical ciphers — Caesar, Atbash, Affine, Vigenère, Hill, Nihilist, Baconian, Porta, Pollux, Morbit, Fractionated Morse, Aristocrats, Patristocrats, Xenocrypts, and more — plus a solver for cryptarithms (puzzles like SEND + MORE = MONEY). A chatbot explains each step so users learn the underlying technique, not just get an answer.

How it works

The project has three parts working together:

  1. A deterministic cipher engine — pure math/code that encrypts and decrypts any cipher when the key is known. No AI involved, just correct implementations of each algorithm.
  2. A cryptanalysis solver — for ciphers meant to be "cracked" without a key (mainly Aristocrats/Patristocrats and Vigenère), using frequency analysis, quadgram scoring, and hill-climbing/simulated annealing search. This is the actual AI/ML part of the project.
  3. A cryptarithm solver — solves letter-arithmetic puzzles (e.g. SEND + MORE = MONEY, where each letter stands for a unique digit) using constraint-satisfaction search rather than language-frequency techniques.

Why this project

Classical ciphers are a great sandbox for combining algorithmic thinking (implementing exact cipher math) with applied AI/ML techniques (frequency analysis, language modeling, and search-based optimization for code-breaking). This project was built to explore both sides — clean deterministic implementations plus a from-scratch cryptanalysis engine — wrapped in a conversational interface that explains its reasoning.

A chatbot layer (powered by the Anthropic API) sits on top of both: it parses what the user is asking for in plain English, calls the right cipher or solver function, and explains the result step by step — like a tutor, not just a calculator.

Repo structure

This project is split across two repositories:

  • ai-cipher-decoder-frontend — plain HTML/CSS/JS. No framework, no build step.
  • ai-cipher-decoder-backend — Python + FastAPI, hosts the cipher engine, solvers, and chatbot orchestration.

Frontend (ai-cipher-decoder-frontend)

ai-cipher-decoder-frontend/
├── index.html          # landing page
├── practice.html        # practice mode (timer, random ciphertext, reveal steps)
├── solve.html            # manual encrypt/decrypt tool
├── cryptarithm.html      # cryptarithm puzzle solver (SEND + MORE = MONEY style)
├── chat.html             # chatbot interface
├── css/                  # per-page + shared styles
│   └── cryptarithm.css
├── js/
│   ├── api.js             # fetch wrappers calling the backend
│   ├── ciphers-ui.js       # shared cipher-selector logic
│   ├── solve.js
│   ├── practice.js
│   ├── cryptarithm.js      # puzzle input parsing + rendering solved digit mapping
│   ├── chat.js
│   └── utils.js
└── assets/

Backend (ai-cipher-decoder-backend)

ai-cipher-decoder-backend/
├── app/
│   ├── main.py            # FastAPI entrypoint
│   ├── ciphers/            # keyed encrypt/decrypt for every supported cipher
│   ├── solvers/             # quadgram scoring, hill-climbing, Aristocrat/Vigenère crackers
│   │   └── cryptarithm_solver.py  # constraint-satisfaction solver for letter-arithmetic puzzles
│   ├── data/                 # English + Spanish quadgram frequency tables
│   ├── chatbot/               # Anthropic API client, tool definitions, orchestrator
│   ├── routes/                 # /encrypt, /decrypt, /solve, /cryptarithm, /chat endpoints
│   └── tests/
├── requirements.txt
└── .env.example

Getting started

Backend

cd ai-cipher-decoder-backend
python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env             # add your ANTHROPIC_API_KEY
uvicorn app.main:app --reload

Backend runs at http://localhost:8000.

Frontend

No build step required — just open the HTML files directly in a browser, or serve the folder locally:

cd ai-cipher-decoder-frontend
python -m http.server 5500

Then visit http://localhost:5500. Make sure js/api.js points at your backend URL (http://localhost:8000 while developing).

Roadmap

  • Phase 1 — Cipher engine: Caesar, Atbash, Affine, Vigenère
  • Phase 1 — Cipher engine: Hill, Nihilist, Baconian, Porta, Pollux, Morbit, Fractionated Morse
  • Phase 2 — Aristocrat/Patristocrat auto-solver (quadgram + hill-climbing)
  • Phase 2 — Vigenère auto-solver (Kasiski + Index of Coincidence)
  • Phase 2 — Xenocrypt (Spanish) solver
  • Phase 2 — Cryptarithm solver (constraint-satisfaction search over letter-digit assignments)
  • Phase 3 — Chatbot orchestration via Anthropic API tool use
  • Phase 4 — Practice mode with timer and step-by-step reveal
  • Deploy frontend (Netlify/Vercel/GitHub Pages) + backend (Render/Railway)

Resources used

License

TBD

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors