Production-grade NCR3 encryption CLI — encrypt, decrypt and verify files from any terminal.
Project description
ncr-cipher
Production-grade file encryption CLI — a single ncr command available everywhere in your terminal after installation, on Windows, macOS, and Linux.
Built on the NCR3 cipher — a combinatorics-based encryption scheme using binomial coefficients (nCr) as a trapdoor, with CBC chaining, HMAC-SHA3-256 authentication, and scrypt KDF.
Installation
pip install ncr-cipher
After install, ncr is available in any terminal — CMD, PowerShell, bash, zsh, fish.
Quick Start
# Generate a key file (do this once)
ncr --keygen mykey.key
# Encrypt a file → creates secret.txt.ncr3
ncr --lock secret.txt --key mykey.key
# Decrypt it back
ncr --unlock secret.txt.ncr3 --key mykey.key
# Verify file integrity without decrypting
ncr --verify secret.txt.ncr3 --key mykey.key
# Show file metadata (no password needed)
ncr --info secret.txt.ncr3
All Commands
| Command | Description |
|---|---|
ncr --keygen <keyfile> |
Generate a new encrypted key file |
ncr --lock <file> --key <k> |
Encrypt a file |
ncr --unlock <file> --key <k> |
Decrypt a file |
ncr --verify <file> --key <k> |
Check HMAC without decrypting — exits 0 (OK) or 1 (TAMPERED) |
ncr --info <file> |
Show NCR version, IV, block count, file size |
ncr --bench |
Benchmark KDF time + encrypt speed at multiple sizes |
ncr --test |
Run internal self-tests — exits 0 (pass) or 1 (fail) |
ncr --version |
Print version |
Flags
| Flag | Description |
|---|---|
--key, -k <file> |
Key file for lock / unlock / verify |
--out, -o <path> |
Output path override |
--inplace, -i |
Overwrite the original file instead of creating new |
--silent, -s |
No output except fatal errors (for shell scripts) |
--force, -f |
Overwrite output without confirmation prompt |
--pow <1-5> |
KDF strength preset (default 3). Higher = slower but stronger. |
--pow levels
| Level | Speed | RAM | Time |
|---|---|---|---|
| 1 | Fast | 16 MB | ~0.1s |
| 2 | Moderate | 32 MB | ~0.3s |
| 3 | Default | 64 MB | ~1s |
| 4 | Strong | 256 MB | ~4s |
| 5 | Maximum | 1 GB | ~16s |
Python API
from ncr_cipher import core
# Encrypt bytes directly
ct = core.encrypt(b"hello world", b"my password", strength=3)
pt = core.decrypt(ct, b"my password")
# Generate / load key files
kf = core.generate_keyfile(b"my password", strength=3)
passphrase = core.load_keyfile(kf, b"my password")
# Verify HMAC without decrypting
ok = core.verify_hmac(ct, b"my password") # True / False
# Parse header without password
hdr = core.parse_header(ct)
# hdr = {"version": "NCR3", "strength": 3, "iv": "...", "block_count": 11, ...}
The NCR3 Cipher
For each byte b at position i:
k_i = BLAKE2b(stream_key, i) mod 256 ← per-byte key mixing
P = (nCr(n1,b) × nCr(n2,255-b) + nCr(n3, b XOR k_i)) mod M
S_i = HMAC-SHA3-256(stream_key, i) mod M ← CBC stream salt
C_i = (P + S_i + C_{i-1}) mod M ← CBC chaining
M = 2¹²⁷ − 1 (Mersenne prime)
n1, n2, n3 = secret integers derived from password via scrypt
Security layers:
- Triple nCr trapdoor — attacker must find all 3 secret integers
- CBC chaining — 1-bit change cascades through entire ciphertext
- BLAKE2b stream — same byte encrypts differently at every position
- scrypt KDF — brute-forcing passwords is expensive
- HMAC-SHA3-256 — any modification detected before decryption
Backwards compatible: reads NCR2 files (read-only).
Requirements
- Python 3.9+
- Zero external dependencies — stdlib only
License
MIT — see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ncr_cipher-1.0.1.tar.gz.
File metadata
- Download URL: ncr_cipher-1.0.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffcd3db1b49357f31d7d615261f9954f57ae1c526cbe0c39cf033b53591475fa
|
|
| MD5 |
b2ed432bc74fd428bc91df6fdfc7bfb4
|
|
| BLAKE2b-256 |
cd239d2264abe9e01babd5c37bf4fcbcc2562efe8600585167f2c89a324342d9
|
File details
Details for the file ncr_cipher-1.0.1-py3-none-any.whl.
File metadata
- Download URL: ncr_cipher-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65098133281310f1a3bccefad05f2b71960b6f192617d99d3c1655a987335a0d
|
|
| MD5 |
534dfe08052fcecaac7d3dcf1c0891e8
|
|
| BLAKE2b-256 |
6c4aac0f9a00c9e8efa611775cd9391ab9fad08c59a810d8c3a1aa6bc6df7854
|