Skip to content

armasahar/Cipher-Utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cipher-utils - Pure JavaScript Cipher Implementation

Ever wondered how ciphers really work under the hood? cipher-utils lets you explore three classic encryption algorithms - ROT13, Base64, and XOR cipher - implemented purely in JavaScript, with zero dependencies and no complex regex patterns.

Installation

npm install cipher-utils

Getting Started

Import specific functions or grab the entire package:

// Pick what you need
import { rot13, encode, decode, encrypt, decrypt } from 'cipher-utils';

// Or import everything
import CipherUtils from 'cipher-utils';
const { rot13, encode, decode, encrypt, decrypt } = CipherUtils;

ROT13 - The Simple Letter Shifter

ROT13 shifts each letter 13 positions in the alphabet. Run it twice and you're back to square one!

import { rot13 } from 'cipher-utils';

const text = 'Hello, World!';
console.log(rot13(text)); // Output: Uryyb, Jbeyq!
console.log(rot13('Uryyb, Jbeyq!')); // Back to: Hello, World!

Base64 - Built from Scratch

No Buffer magic here! Just pure JavaScript implementation of Base64 encoding:

import { encode, decode } from 'cipher-utils';

const text = 'Hello, World!';
console.log(encode(text)); // Output: SGVsbG8sIFdvcmxkIQ==
console.log(decode('SGVsbG8sIFdvcmxkIQ==')); // Back to: Hello, World!

// Short strings get padding:
console.log(encode('Test')); // Output: VGVzdA==

XOR Cipher - Simple Symmetric Encryption

Perfect for casual obfuscation (not Fort Knox level security!). Use the same key to encrypt and decrypt:

import { encrypt, decrypt } from 'cipher-utils';

const message = 'Secret message';
const key = 'my_secret_key';

const encrypted = encrypt(message, key);
console.log(encrypted); // Hex string

const decrypted = decrypt(encrypted, key);
console.log(decrypted); // Back to: Secret message

API Reference

  • rot13(inputString) → Returns ROT13 transformed string
  • encode(inputString) → Returns Base64 encoded string
  • decode(base64String) → Returns decoded string
  • encrypt(inputString, key) → Returns hex-encoded encrypted string
  • decrypt(hexInput, key) → Returns decrypted string

Why Use cipher-utils?

  • Zero dependencies keeps your project lean
  • No regex complexity to deal with
  • Pure JavaScript implementation you can easily understand
  • Great for learning how ciphers actually work
  • Perfect for educational projects or simple encryption needs

Contributing

Fork the repository. Create a feature branchAdd tests for your changes. Submit a pull request.

License

MIT Licensed - feel free to use and modify as needed.

About

Utility functions for encryption, decryption of cryptographic algorithms

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published