Skip to content

[FEATURE] Add Four-Square Cipher Module (Classical Digraph Cipher) #254

Description

@Aakif-Kohari

Summary

The Classical category currently has Playfair as its only digraph substitution cipher. Four-Square (Delastelle) is a related but distinct construction (uses 4 separate 5x5 grids instead of 1) that pairs naturally with the existing Playfair implementation and reuses much of its grid-construction logic pattern.

What's missing

  • No lib/cipher/four-square.ts
  • No visualizer entry, worker routing, or tests

Proposed implementation

  • Build two keyed 5x5 grids (top-right and bottom-left) plus two standard A-Z (I/J merged) grids (top-left plaintext grid, bottom-right ciphertext grid), following the same bigram-preparation rules as Playfair (pad odd length, uppercase, strip non-alpha)
  • Digraph substitution: for plaintext pair (a,b), find a in top-left grid, b in bottom-right grid, take the row/column intersection rule across the 4-grid layout
  • Steps: grid construction (4 matrices) + per-bigram substitution, reusing the matrix/highlight step schema Playfair already uses
  • Security status: legacy
  • Test vectors: use the standard published Four-Square worked example

Acceptance criteria

  • Round-trip encrypt/decrypt correct
  • Matches published Four-Square test vector
  • Handles odd-length input and duplicate-letter bigrams like Playfair does
  • Unit + fuzz tests
  • Dark/light mode support via existing theme system

Assignment

I'd like to work on this issue under ECSoC26. Will open a PR only after approval/assignment by @csxark or another maintainer.

Metadata

Metadata

Assignees

Labels

ECSoC26Elite Coders Summer of Code 2026

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions