random-universe-cipher
v1.0.1
Published
Random Universe Cipher - A quantum-resistant symmetric block cipher
Maintainers
Readme
Random Universe Cipher (RUC)
A quantum-resistant symmetric block cipher with 256-bit security. Protects data against both classical and quantum computing attacks.
Links
- Live Tool: https://rosettascript.github.io/tools/random-universe-cipher
- Blog Post: https://rosettascript.github.io/blogs/random-universe-cipher-ruc-post-quantum-security
- GitHub: https://github.com/rosettascript/random-universe-cipher
Why RUC?
Traditional ciphers like AES and ChaCha20 may become vulnerable when quantum computers become mainstream. RUC is designed from the ground up to resist quantum attacks while maintaining exceptional security against classical cryptanalysis.
Installation
npm install random-universe-cipherQuick Start
import { encrypt, decrypt, deriveKeyFromPassword } from 'random-universe-cipher';
// Derive key from password
const keyMaterial = await deriveKeyFromPassword('my-password', 'salt');
// Encrypt
const plaintext = new TextEncoder().encode('Hello, World!');
const encrypted = encrypt(plaintext, keyMaterial.key, keyMaterial.iv);
// Decrypt
const decrypted = decrypt(encrypted, keyMaterial.key, keyMaterial.iv);
console.log(new TextDecoder().decode(decrypted)); // "Hello, World!"Security Specifications
| Parameter | Value | |-----------|-------| | Key Size | 512 bits (64 bytes) | | Block Size | 256 bits (32 bytes) | | Rounds | 24 (fixed) | | Security Level | 256-bit post-quantum | | Classical Security | 512 bits | | Quantum Security | 256 bits |
How It Works
Core Design Principles
Confusion - Complex, non-linear relationship between key and ciphertext:
- Galois Field (GF) multiplication for algebraic complexity
- 24 unique S-boxes generated from the master key
- Dynamic selector-based register routing
Diffusion - Small input changes cause large output changes:
- 7 state registers (512 bits each) = 3,584 bits internal state
- 1,024-bit accumulator collects transformation results
- SHAKE256 keystream ensures maximum diffusion
Security - Resistance against cryptanalytic attacks:
- 24 rounds provide sufficient mixing
- S-boxes with high non-linearity (≥ 100)
- Large state resists various attack vectors
Architecture
Key (512-bit) ──┬──> SHAKE256 ──> State Registers R[0..6]
├──> SHAKE256 ──> Selectors SEL[0..N]
├──> SHAKE256 ──> Round Keys RK[0..23]
└──> SHAKE256 ──> S-Boxes S[0..23]
IV + State ──> mix_iv_into_state() ──> Initialized State
For each block:
State + Selectors + Round Keys + S-Boxes ──> 24 Rounds ──> Accumulator
Accumulator + Final State ──> SHAKE256 ──> Keystream
Plaintext XOR Keystream ──> CiphertextAPI
Key Derivation
// Async key derivation (recommended - uses Argon2id)
const keyMaterial = await deriveKeyFromPassword('password', 'salt');
// Sync key derivation (uses SHAKE256)
const keyMaterial = deriveKeySync('password', 'salt');
// Generate random salt
const salt = generateSalt();
// Generate random key/IV
const key = generateRandomKey();
const iv = generateRandomIV();Encryption
// CTR mode (default)
const encrypted = encrypt(plaintext, key, iv);
const decrypted = decrypt(ciphertext, key, iv);
// CBC mode
const encrypted = encryptCBC(plaintext, key, iv);
const decrypted = decryptCBC(ciphertext, key, iv);
// Single block
const ciphertext = encryptBlock(plaintext, key, iv, 0n, state, keyMaterial);AEAD (Authenticated Encryption)
// Encrypt with authentication
const result = await aeadEncrypt(plaintext, key, iv, 'additional-data');
const decrypted = await aeadDecrypt(result.ciphertext, key, result.tag, 'additional-data');
// String convenience
const encrypted = await aeadEncryptString('message', 'password');
const decrypted = await aeadDecryptString(encrypted, 'password');Low-Level API
import {
expandKey,
mixIVIntoState,
generateSBox,
encryptBlock,
createCipherState
} from 'random-universe-cipher';
// Generate S-boxes
const sbox = generateSBox(key);
// Expand key
const keyMaterial = expandKey(key);
// Mix IV into state
const state = mixIVIntoState(keyMaterial.registers, iv);
// Encrypt single block
const ciphertext = encryptBlock(plaintext, key, iv, 0n, state, keyMaterial);Requirements
- Node.js 18+ or modern browser
@noble/hashes(installed as dependency)
Disclaimer
This is a demonstration implementation. The cipher has not been audited for production use. Use at your own risk.
License
MIT
