npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

bazeries-cipher

v1.0.0

Published

Tiny dependency-free TypeScript implementation of the Bazeries cipher (digit-keyed transposition + keyed substitution).

Readme

bazeries-cipher

test license: MIT

A tiny, dependency-free TypeScript implementation of the Bazeries cipher — Étienne Bazeries' (1846–1931) two-stage product cipher combining a digit-keyed transposition with a keyed substitution, all driven by a single secret number.

Powers the free, in-browser decoder at Text Machine → Bazeries cipher — paste a number key and ciphertext, decode instantly, nothing leaves your browser.

🔎 Not sure your ciphertext is even Bazeries? Run it through the Cipher Identifier first — it fingerprints unknown ciphertext (frequency, Index of Coincidence, χ² tests) and points you to the right decoder.

Install

npm install bazeries-cipher

Or just copy src/bazeries-cipher.ts into your project — it has zero dependencies.

Usage

import { encode, decode } from "bazeries-cipher";

encode("DCODE", "23");                 // → "DLSLO"   (the canonical test vector)
decode("DLSLO", "23");                 // → "DCODE"

encode("WE HAVE TAKEN THE BRIDGE", "23");
// → "SCYTFPSSUTPGHSFMBSRL"

// Round-trips for any valid number key:
decode(encode("ATTACKATDAWN", "1947"), "1947"); // → "ATTACKATDAWN" (J folded to I)

The key is a number (1…999999). Leading zeros are insignificant ("023" === 23). A digit 0 in the key means a transposition group of length 10.

How it works

A single secret number drives both stages:

  1. Transposition. The plaintext is cut into runs whose lengths are the successive digits of the number (cycled), and each run is reversed. With key 23 the stream is split 2, 3, 2, 3, … and every group flipped.
  2. Substitution. Two 5×5 squares (I/J merged → 25 letters) sit side by side. Square 1 is the plain alphabet written down the columns; square 2 is keyed by the number spelled out in words (23 → "TWENTYTHREE") and written across the rows. Each transposed letter is located in square 1 and replaced by the letter at the same cell of square 2.

The squares' opposite fill directions (square 1 by column, square 2 by row) are intrinsic to the classic definition — they are exactly what make the canonical vector DCODE / 23 → DLSLO come out right. Decoding reverses the two stages.

Non-letters are dropped and J is folded onto I, so the cipher operates on the 25-letter alphabet only (output is recovered minus spacing/punctuation).

API

| Export | Description | | --- | --- | | encode(text, key?) | Encipher plaintext (key defaults to "23"). | | decode(text, key?) | Decipher ciphertext. | | applyBazeries(text, key, "encode" \| "decode") | The underlying engine. | | checkNumber(raw) / numberValue(raw) | Validate / parse a key. | | spellNumber(n) | The English spelling that keys square 2 (23 → "TWENTYTHREE"). | | buildGrid1() / buildGrid2(keyword) / gridRows(grid) | Build / lay out the squares. |

Tests

npm test

Pins the canonical DCODE/23 → DLSLO vector, the longer WEHAVETAKENTHEBRIDGE/23 → SCYTFPSSUTPGHSFMBSRL vector, and random round-trips (including internal and leading-zero keys).

License

MIT — see LICENSE. Part of the Text Machine collection of free, privacy-first text tools (31 classical ciphers and counting).