Lightweight text encryption & decryption combining Vigenère and Affine ciphers — works in Node.js.
ciphex implements a combined Vigenère and Affine cipher. It maps each character by first applying a Vigenère shift using a key stored in key.env, followed by an Affine transformation (multiplication and addition):
E(x) = ((x + v) · a + b) mod 96
D(x) = (a⁻¹ · (x - b) - v) mod 96
where v is the Vigenère character shift, b is the additive shift key, and a is a multiplicative key coprime to 96.
It operates on all 96 printable ASCII characters (space → ~), making it suitable for encrypting plain text strings.
├── CONTRIBUTING.md # Contribution file,
├── LICENSE # License file.
├── README.md # Documentation.
├── index.js # Entry script file.
├── key.env # Vigenère secret key configuration.
├── package.json # Node packages & Project's metadata.
└── test.js # Test script file.- Language: JavaScript
- Runtime: Node.js
npm install ciphexciphex requires a key.env file located in the same directory as the module for the Vigenère cipher base:
key.env
Create a key.env in your directory and set a string of your chooice as the value of the key.
key = "SOMETHING"Code
const { encrypt, decrypt, generateKeys } = require("ciphex");
const keys = generateKeys(); // [b, a] — random valid key pair
const cipher = encrypt("hello!", keys);
const plain = decrypt(cipher, keys); // "hello!"
console.log(keys); // e.g. [42, 17]
console.log(cipher); // encrypted string
console.log(plain); // hello!Important: You must use the same
keysarray for bothencryptanddecrypt. Store or transmit keys securely alongside your ciphertext if needed. Thekey.envmust also map to the same Vigenère key during decryption.
Returns a [b, a] key pair where:
b— any integer in[0, 95]a— any integer in[1, 95]that is coprime to 96 (i.e., has a modular inverse)
text— plaintext string (printable ASCII only)keys—[b, a]fromgenerateKeys()- Slices the Vigenère key secretly from
key.env. - Returns the encrypted string, or
nulliftextisnull
text— previously encrypted stringkeys— same[b, a]used during encryption- Requires the same Vigenère key in
key.env. - Returns the decrypted plaintext string, or
nulliftextisnull
Internal helper — returns the modular inverse of a under mod 96. Exported for testing purposes.
ciphex works on all 96 printable ASCII characters — character codes 32–127:
(space) ! " # $ % & ' ( ) * + , - . / 0–9 : ; < = > ? @
A–Z [ \ ] ^ _ ` a–z { | } ~
Characters outside this range (e.g. emojis, unicode accents) are not supported and will produce unexpected output.
Contributions are welcome! See CONTRIBUTING.md for open issues, good first tasks, and the contribution workflow.
MIT © Rohan S Mirjankar