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
Markdown
# ๐ password-obscura
[](https://www.npmjs.com/package/password-obscura)
[](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.**