UNPKG

base53-encoder

Version:

A unique Base53 encoding scheme with 30-bit block and 5-bit segment encoding

118 lines (79 loc) 2.29 kB
# base53-encoder ## Overview `base53-encoder` is a unique Base53 encoding scheme that provides a flexible and innovative approach to string encoding and key generation. Inspired by traditional base encoding methods, this library offers a custom 30-bit block encoding strategy with 5-bit segments. ## Features - 🔢 Custom 32-character encoding table - 🧩 5-bit segment encoding - 🔒 Flexible key generation - 🔄 Robust encode and decode methods - 🚀 Lightweight and easy to use - 🌐 ESM module support ## Installation Install the package using npm: ```bash npm install base53-encoder ``` ## Usage ### Basic Encoding and Decoding ```javascript import Base53 from 'base53-encoder'; // Encode a string const encoded = Base53.encode('Hello, World!'); console.log(encoded); // Decode a string const decoded = Base53.decode(encoded); console.log(decoded); // 'Hello, World!' ``` ### Key Generation ```javascript // Generate a 150-bit key const key = Base53.buildKey(); console.log(key.rawKey); // Original random key console.log(key.encodedKey); // Encoded key console.log(key.decodedKey); // Decoded key ``` ### Customizing Key Generation ```javascript // Custom key generation const customKey = Base53.buildKey( 3, // Number of segments 24 // Length of each segment ); ``` ## Encoding Strategy ### Technical Details - **Encoding Table**: 32 unique characters - **Segment Size**: 5 bits - **Block Size**: 30 bits (6 segments) - **Padding**: Automatic padding to ensure full block encoding ### Unique Characteristics - Mimics Base64 encoding - Custom 5-bit segment approach - Flexible key generation - Built-in error handling ## Error Handling The library throws an error for invalid encoded strings: ```javascript try { Base53.decode('Invalid&Characters'); } catch (error) { console.error('Encoding error:', error.message); } ``` ## Performance `base53-encoder` is designed to be lightweight and efficient, with minimal overhead for encoding and decoding operations. ## Compatibility - Node.js v14.16+ - ESM module support ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. ## License MIT License ## Author [Your Name] Nate ## Keywords - encoding - base53 - encryption - key-generation ```