UNPKG

password-obscura

Version:

A lightweight NPM package to visually obscure passwords or strings using customizable shift-based and symbol-mapping logic. Inspired by Caesar Cipher โ€” reimagined for modern devs.

576 lines (415 loc) โ€ข 16.7 kB
# ๐Ÿ” password-obscura [![npm version](https://img.shields.io/npm/v/password-obscura.svg)](https://www.npmjs.com/package/password-obscura) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) A lightweight NPM package to "visually" obscure passwords or strings using customizable shift-based and symbol-mapping logic. Inspired by Caesar Cipher โ€” reimagined for modern developers with advanced multi-table encryption capabilities. ## ๐Ÿ” What It Does Instead of strong encryption (which is better handled by libs like bcrypt), this tool is meant for: - ๐Ÿ”’ Obscuring passwords for display (e.g., showing a fake-but-consistent password to users) - ๐Ÿงช Generating pseudo-random but reversible representations - ๐Ÿ“œ Teaching cryptography basics (Caesar, Atbash, ROT13, Vigenรจre, etc.) - ๐ŸŽจ Creative text transformations with emojis and symbols - ๐Ÿ”ง Advanced cipher combinations for educational purposes ## โœ… Use Cases - ๐ŸŽฎ Fun CLI tools and interactive applications - ๐Ÿ” Password managers showing masked variants - ๐Ÿค– Discord / game bots that hide inputs creatively - ๐ŸŽ“ Educational demos on encryption basics and cryptography - ๐Ÿ“ Obfuscating config keys or token snippets in logs - ๐Ÿงช Testing and demonstration of cipher algorithms - ๐ŸŽญ Creative text art and visual transformations ## ๐Ÿง  Features - **7 Cipher Methods**: Complete encryption toolkit for various use cases - `caesar` - Classic Caesar cipher with customizable shift - `rot13` - ROT13 cipher (shift by 13, self-inverse) - `symbolMap` - Replace characters with custom symbols/emojis - `mirror` - Atbash cipher (a โ†” z, b โ†” y, etc.) - `multiTable` - **Advanced!** Multi-table Caesar with dynamic shift patterns - `polyalphabetic` - **Advanced!** Keyword-based Vigenรจre-style cipher - `advanced` - **Advanced!** Multi-layer cipher with various transformations - **Dynamic Shift Patterns**: Five sophisticated pattern algorithms - **Even-Odd**: Alternates between two shift values based on position - **Fibonacci**: Uses Fibonacci sequence for progressive shifts - **Prime Numbers**: Applies prime number sequence for shifts - **Progressive**: Incrementally increases shift value per character - **Custom Sequences**: User-defined shift patterns - **Advanced Capabilities**: - **Multi-table Support**: Use different alphabets for enhanced complexity - **Keyword Ciphers**: Polyalphabetic encryption with repeating keywords - **Layer Combinations**: Stack multiple cipher techniques together - **Perfect Reversibility**: All ciphers maintain encode/decode symmetry - **Developer Experience**: - ๐ŸŽฏ **TypeScript First**: Full type safety with comprehensive interfaces - ๐Ÿชถ **Lightweight**: 8.3 kB package size, zero runtime dependencies - ๐ŸŒ **Universal**: Works in Node.js and browser environments - โšก **Fast**: Optimized algorithms with excellent performance - ๐Ÿ› ๏ธ **CLI Tool**: Complete command-line interface included ## ๐Ÿ“ฆ Installation ```bash # npm npm install password-obscura # yarn yarn add password-obscura # pnpm pnpm add password-obscura # bun bun add password-obscura ``` ## ๐Ÿงช API Usage ### Basic Examples ```typescript import { obscure, reveal } from "password-obscura"; // Caesar-style shift const hidden = obscure("secret123", { method: "caesar", shift: 3 }); console.log(hidden); // โ†’ "vhfuhw123" const original = reveal(hidden, { method: "caesar", shift: 3 }); console.log(original); // โ†’ "secret123" // ROT13 const rot13Hidden = obscure("hello-world", { method: "rot13" }); console.log(rot13Hidden); // โ†’ "uryyb-jbeyq" // Mirror/Atbash cipher const mirrored = obscure("hello", { method: "mirror" }); console.log(mirrored); // โ†’ "svool" // Symbol mapping with emojis const emojiHidden = obscure("abc123", { method: "symbolMap" }); console.log(emojiHidden); // โ†’ "๐Ÿ”ฅโญ๐ŸŒŸ๐ŸŸ ๐ŸŸก๐ŸŸข" ``` ### Advanced Multi-Table Ciphers ```typescript import { obscure, reveal, DynamicTableConfig } from "password-obscura"; // Multi-table Caesar with even-odd pattern const tableConfig: DynamicTableConfig = { tables: ["abcdefghijklmnopqrstuvwxyz", "zyxwvutsrqponmlkjihgfedcba"], shiftPattern: "even-odd", baseShift: 3, }; const multiResult = obscure("Hello World", { method: "multiTable", tableConfig, }); console.log(multiResult); // โ†’ "Kaohr Zkuhg" // Fibonacci shift pattern const fibConfig: DynamicTableConfig = { tables: ["abcdefghijklmnopqrstuvwxyz"], shiftPattern: "fibonacci", baseShift: 1, }; const fibResult = obscure("ABCDEFGHIJK", { method: "multiTable", tableConfig: fibConfig, }); console.log(fibResult); // โ†’ "BCEGJNTCQMV" // Custom shift sequence const customConfig: DynamicTableConfig = { tables: ["abcdefghijklmnopqrstuvwxyz"], shiftPattern: "custom", baseShift: 1, customShifts: [1, 3, 5, 7, 2, 4, 6, 8], }; ``` ### Polyalphabetic Cipher ```typescript import { obscure, reveal, PolyalphabeticConfig } from "password-obscura"; const polyConfig: PolyalphabeticConfig = { keyword: "SECRET", }; const polyResult = obscure("Hello World", { method: "polyalphabetic", polyConfig, }); console.log(polyResult); // โ†’ "Oinus Mstuh" const decrypted = reveal(polyResult, { method: "polyalphabetic", polyConfig }); console.log(decrypted); // โ†’ "Hello World" ``` ### Advanced Multi-Layer Cipher ```typescript const layers = [ { type: "shift", config: { shift: 3 } }, { type: "table", config: { tables: ["abcdefghijklmnopqrstuvwxyz", "zyxwvutsrqponmlkjihgfedcba"], shiftPattern: "fibonacci", baseShift: 2, }, }, { type: "reverse" }, ]; const advancedResult = obscure("Secret Message", { method: "advanced", layers, }); console.log(advancedResult); // โ†’ Complex multi-layer transformation ``` ### Advanced Symbol Mapping ```typescript import { obscure, reveal, SymbolMapConfig } from "password-obscura"; // Custom symbol mapping const customMap: SymbolMapConfig = { a: "๐ŸŒŸ", b: "๐Ÿš€", c: "๐Ÿ’Ž", "1": "โญ", "2": "๐Ÿ”ฅ", "3": "๐Ÿ’ซ", }; const customHidden = obscure("abc123", { method: "symbolMap", symbolMap: customMap, }); console.log(customHidden); // โ†’ "๐ŸŒŸ๐Ÿš€๐Ÿ’Žโญ๐Ÿ”ฅ๐Ÿ’ซ" const restored = reveal(customHidden, { method: "symbolMap", symbolMap: customMap, }); console.log(restored); // โ†’ "abc123" ``` ## ๐Ÿ› ๏ธ CLI Usage The package includes a convenient CLI tool: ```bash # Install globally (optional) npm install -g password-obscura # Or use with npx npx password-obscura --help ``` ### CLI Examples ```bash # Basic Caesar cipher $ npx password-obscura encode "hello-world" --method caesar --shift 3 khoor-zruog $ npx password-obscura decode "khoor-zruog" --method caesar --shift 3 hello-world # ROT13 (self-inverse) $ npx password-obscura encode "hello-world" --method rot13 uryyb-jbeyq # Mirror/Atbash cipher $ npx password-obscura encode "secret" --method mirror hvxivg # Symbol mapping with emojis $ npx password-obscura encode "abc123" --method symbolMap ๐Ÿ”ฅโญ๐ŸŒŸ๐ŸŸ ๐ŸŸก๐ŸŸข # Advanced multi-table with Fibonacci pattern $ npx password-obscura encode "Hello World" --method multiTable --pattern fibonacci Iukpt Fkzll # Polyalphabetic cipher with keyword $ npx password-obscura encode "Secret Message" --method polyalphabetic --keyword "CIPHER" Wmryic Qmtslmi # Custom shift sequences $ npx password-obscura encode "test" --method multiTable --pattern custom --custom-shifts "1,3,5,7" ubxm # Advanced multi-layer cipher (uses default layers) $ npx password-obscura encode "Complex Text" --method advanced txfI fmofhxmC ``` ## ๐Ÿ“– API Reference ### `obscure(input: string, options: ObscureOptions): string` Obscures the input string using the specified method. **Parameters:** - `input`: The string to obscure - `options`: Configuration object (see ObscureOptions below) ### `reveal(input: string, options: ObscureOptions): string` Reveals the obscured string using the same method and options used to obscure it. **Parameters:** - `input`: The obscured string to reveal - `options`: Same configuration object used for obscuring ### Types ```typescript interface ObscureOptions { method: | "caesar" | "rot13" | "symbolMap" | "mirror" | "multiTable" | "polyalphabetic" | "advanced"; // Caesar cipher options shift?: number; // default: 3 // Symbol mapping options symbolMap?: SymbolMapConfig; // Multi-table cipher options tableConfig?: DynamicTableConfig; // Polyalphabetic cipher options polyConfig?: PolyalphabeticConfig; // Advanced cipher options layers?: Array<{ type: "table" | "shift" | "reverse" | "transpose"; config?: any; }>; } interface SymbolMapConfig { [key: string]: string; } interface DynamicTableConfig { tables: string[]; shiftPattern: "even-odd" | "fibonacci" | "prime" | "progressive" | "custom"; baseShift?: number; customShifts?: number[]; } interface PolyalphabeticConfig { keyword: string; tables?: string[]; } ``` ### Constants ```typescript // Pre-defined symbol mapping with emojis for all alphanumeric characters DEFAULT_SYMBOL_MAP: SymbolMapConfig; // Four pre-defined alphabet tables for multi-table ciphers DEFAULT_TABLES: string[]; ``` ## ๐Ÿ” Method Details ### Basic Cipher Methods #### Caesar Cipher Classic Caesar cipher that shifts letters by a specified amount. - โœ… Preserves case and non-alphabetic characters - โœ… Default shift: 3, supports any shift value - โœ… Mathematically sound with modular arithmetic #### ROT13 Special case of Caesar cipher with a shift of 13. - โœ… Self-inverse (encoding and decoding are the same operation) - โœ… Commonly used in online forums - โœ… Fixed 13-character shift for consistency #### Symbol Map Replaces characters with custom symbols or emojis. - โœ… Includes default emoji mapping for all alphanumeric characters - โœ… Fully customizable with your own symbol mappings - โœ… Perfect for creative obfuscation and visual appeal - โœ… Handles Unicode characters properly #### Mirror (Atbash) Maps each letter to its mirror position in the alphabet (Aโ†”Z, Bโ†”Y, etc.). - โœ… Self-inverse like ROT13 - โœ… Ancient cipher method with historical significance - โœ… Case-preserving transformation ### Advanced Cipher Methods #### Multi-Table Caesar Uses multiple substitution alphabets with dynamic shift patterns. - ๐Ÿš€ **5 Shift Patterns**: even-odd, fibonacci, prime, progressive, custom - ๐Ÿš€ **Multiple Tables**: Switch between different alphabets per character - ๐Ÿš€ **Perfect Reversibility**: All patterns maintain encode/decode symmetry - ๐Ÿš€ **Educational Value**: Demonstrates polyalphabetic principles **Shift Patterns:** - **Even-Odd**: `position % 2 === 0 ? baseShift : baseShift + 1` - **Fibonacci**: Uses Fibonacci sequence: 1, 1, 2, 3, 5, 8, 13... - **Prime**: Uses prime numbers: 2, 3, 5, 7, 11, 13, 17... - **Progressive**: `baseShift + (position % 10)` - **Custom**: User-defined shift sequences #### Polyalphabetic Cipher Keyword-based Vigenรจre-style encryption. - ๐Ÿ”‘ **Keyword Encryption**: Uses repeating keyword for shift calculation - ๐Ÿ”„ **Dynamic Shifts**: Each keyword character determines shift amount - ๐Ÿ“š **Multiple Tables**: Can use different alphabets for enhanced complexity - ๐ŸŽ“ **Classic Algorithm**: Implements traditional Vigenรจre cipher principles #### Advanced Multi-Layer Cipher Combines multiple cipher techniques in sequence. - ๐Ÿ”— **Layer Composition**: Stack multiple transformations - ๐Ÿ”€ **Transformation Types**: shift, table, reverse, transpose - โš™๏ธ **Configurable**: Custom layer configurations - ๐Ÿ”„ **Reversible**: Applies transformations in reverse order for decoding **Available Layer Types:** - **shift**: Basic Caesar shift transformation - **table**: Multi-table substitution with patterns - **reverse**: String reversal transformation - **transpose**: Block-based character transposition ## โšก Performance & Compatibility ### Performance Benchmarks Based on 100 iterations with long text strings: - **Caesar**: ~34ms (fastest basic cipher) - **ROT13**: ~46ms - **Symbol Map**: ~37ms - **Mirror**: ~19ms (fastest overall) - **Multi-Table**: ~42ms (excellent for complexity) - **Polyalphabetic**: ~51ms - **Advanced**: ~75ms (acceptable for multi-layer) ### Compatibility - โœ… **Node.js**: v16+ (ESM modules) - โœ… **Browsers**: Modern browsers with ES2020 support - โœ… **TypeScript**: Full type definitions included - โœ… **Package Size**: 8.3 kB (40.4 kB unpacked) - โœ… **Dependencies**: Zero runtime dependencies (CLI uses commander) ### ESM Module Support This package uses modern ES modules: ```javascript // โœ… Correct import syntax import { obscure, reveal } from "password-obscura"; // โŒ CommonJS require() not supported const { obscure } = require("password-obscura"); // Won't work ``` ## โš ๏ธ Security Notice This library is designed for **visual obfuscation** and **educational purposes**, not cryptographic security. The transformations are easily reversible and should not be used for protecting sensitive data in production environments. For actual password hashing and security, use established libraries like: - [bcrypt](https://www.npmjs.com/package/bcrypt) - [argon2](https://www.npmjs.com/package/argon2) - [scrypt](https://nodejs.org/api/crypto.html#crypto_crypto_scrypt_password_salt_keylen_options_callback) ## ๐Ÿค Contributing Contributions are welcome! Please feel free to submit a Pull Request. ### Development Setup ```bash # Clone the repository git clone https://github.com/angga-22/password-obscura.git cd password-obscura # Install dependencies npm install # Build the project npm run build # Run comprehensive test suite node demo.js # Test CLI functionality npx password-obscura encode "test" --method caesar --shift 5 ``` ### Project Structure ``` password-obscura/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ index.ts # Main API entry point โ”‚ โ””โ”€โ”€ lib/ # Cipher implementations โ”‚ โ”œโ”€โ”€ caesar.ts # Basic Caesar cipher โ”‚ โ”œโ”€โ”€ rot13.ts # ROT13 implementation โ”‚ โ”œโ”€โ”€ symbolMap.ts # Symbol/emoji mapping โ”‚ โ”œโ”€โ”€ atbash.ts # Mirror/Atbash cipher โ”‚ โ””โ”€โ”€ dynamicCipher.ts # Advanced multi-table ciphers โ”œโ”€โ”€ bin/cli.ts # Command-line interface โ”œโ”€โ”€ demo.js # Comprehensive test suite โ”œโ”€โ”€ dist/ # Built output โ””โ”€โ”€ docs/ # Documentation files ``` ### Versioning This project follows [Semantic Versioning](https://semver.org/). See [VERSIONING.md](VERSIONING.md) for details about our versioning strategy. ### Releases To create a new release: ```bash # For bug fixes npm run release:patch # For new features npm run release:minor # For breaking changes npm run release:major ``` Or use the release script: ```bash ./scripts/release.sh patch ``` ## ๏ฟฝ Troubleshooting & FAQ ### Common Issues **Q: "Cannot use import statement outside a module"** A: This package uses ESM modules. Ensure your project supports ES modules or use Node.js v16+. **Q: Some characters don't encode/decode properly** A: The library is designed for basic Latin characters (a-z, A-Z, 0-9). Special Unicode characters may not be supported in all cipher methods. **Q: Advanced cipher results seem inconsistent** A: This is expected! Advanced ciphers use complex algorithms. Ensure you're using the exact same configuration for both encoding and decoding. **Q: CLI command not found** A: Either install globally with `npm install -g password-obscura` or use `npx password-obscura` prefix. ### Getting Help - ๐Ÿ“– Check the [API documentation](#-api-reference) above - ๐Ÿ” Review the [comprehensive test suite](demo.js) for examples - ๐Ÿ› Report issues on [GitHub Issues](https://github.com/angga-22/password-obscura/issues) - ๐Ÿ’ก Request features or ask questions in [Discussions](https://github.com/angga-22/password-obscura/discussions) ## ๏ฟฝ๐Ÿ“„ License MIT License - see the [LICENSE](LICENSE) file for details. ## ๐Ÿ™ Acknowledgments Inspired by classical cipher techniques and modern developer needs for creative text transformation. Special thanks to: - ๐Ÿ“š **Historical Cryptographers**: Caesar, Vigenรจre, Atbash cipher inventors - ๐ŸŽ“ **Educational Resources**: Cryptography textbooks and online courses - ๐Ÿ’ป **Open Source Community**: TypeScript, Node.js, and npm ecosystem - ๐Ÿงช **Testing**: Comprehensive validation of all cipher implementations --- **Built with โค๏ธ for developers who love creative coding and educational cryptography.**