Skip to content

krondorl/caesar-simd-as-wasm

Repository files navigation

Caeasar cipher using WebAssembly SIMD

Proof of Concept created with AssemblyScript, WASM and Node.js.

Screenshot

Stack

Using these technologies:

  • AssemblyScript
  • JavaScript
  • WebAssembly
  • SIMD
  • Node.js 22

Algorithm

  1. Original Input (v128.load)
  2. Detect Letters (isLetter mask)
  3. Extract Case Bit (caseBit = chunk & 0x20)
  4. Normalize to Uppercase (val = chunk & 0x5F)
  5. Apply Shift (shifted = val + 3)
  6. Wrap Underflow (if < 65, add 26)
  7. Wrap Overflow (if > 90, subtract 26)
  8. Restore Case (result = shifted | caseBit)
  9. Preserve Non-letters (bitselect)

Visualization

The visual of the algorithm is available as a local webpage.

npm run viz

SIMD

Imagine you have to pack 16 lunchboxes with sandwiches.

Instead of making one sandwich at a time (like a normal computer), SIMD (Single Instruction, Multiple Data) lets you use one instruction to make all 16 sandwiches at the exact same time.

It's a way for the computer's processor to do the same operation on many pieces of data simultaneously, which makes complex tasks like video processing or cipher encoding much faster.

Multiplication Example

The SIMD tripling of four 8-bit numbers. The CPU loads 4 numbers at once, multiplies them all in one SIMD-multiplication, and saves them all at once back to RAM. In theory, the speed can be multiplied by 4.

Usage

In the repo root folder level use this command:

npm install
npm asbuild
npm start

License

Please check out LICENSE and NOTICE file.

Links

History

  • 7th October 2025: Refactored SIMD code to be branchless, Visualization
  • 6th October 2025: Initial working PoC

About

Caeasar Cipher Using WebAssembly SIMD

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published