base985161 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  3. package/base985161.js +103 -0
  4. package/package.json +37 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 NoaxH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # BASE-985161 — Binary-to-Text via Big-Integer Conversion
2
+
3
+ **BASE-985161** encodes any byte stream as text using a Unicode alphabet of 985,161 symbols (from U+10000 upward). It preserves leading zero bytes and performs true base conversion (256 <-> 985,161), similar to Base58 but at a much larger radix.
4
+
5
+ ## Why
6
+ - **Unicode-friendly:** copy/paste-safe in editors, browsers, and chats.
7
+ - **Compact-ish:** larger radix -> fewer characters than Base64 for many inputs.
8
+ - **Reversible:** lossless round-trip; leading zeros preserved.
9
+
10
+ ## Web (one-page)
11
+ Open `index.html` in your browser. Type text or upload a file -> **ENCODE**. Paste encoded text -> **DECODE**.
12
+
13
+ ## Python
14
+ ```bash
15
+ python base985161.py enc input.bin out.b985161
16
+ python base985161.py dec out.b985161 restored.bin
17
+ ```
18
+ ```python
19
+ import base985161 # if placed on PYTHONPATH
20
+ s = base985161.encode(b"Hello")
21
+ raw = base985161.decode(s)
22
+ ```
23
+
24
+ ## Node / JavaScript
25
+ ```bash
26
+ npm install base-985161
27
+ # or: npm install -g base-985161
28
+ ```
29
+ ```bash
30
+ node base985161.js enc input.bin out.b985161
31
+ node base985161.js dec out.b985161 restored.bin
32
+ # or via npm bin:
33
+ base985161 enc input.bin out.b985161
34
+ base985161 dec out.b985161 restored.bin
35
+ ```
36
+ ```js
37
+ import { encode, decode } from 'base-985161';
38
+ const s = encode(new TextEncoder().encode('Hello'));
39
+ const raw = decode(s);
40
+ ```
41
+
42
+ ## Design Notes
43
+ - Alphabet: contiguous Unicode range **U+10000 .. U+10000+985160** (avoids surrogates).
44
+ - Method: big-integer division (repeated div/mod) for 256<->985161, preserving leading 0x00 bytes via leading zero-digits.
45
+ - No padding header is needed because conversion is exact in base arithmetic.
46
+
47
+ ## Caveats
48
+ - Some glyphs may render as tofu; that's fine—decoding uses code points, not glyph shapes.
49
+ - Not encryption: this is an encoding, not a security mechanism.
50
+
51
+ ## License
52
+ MIT
package/base985161.js ADDED
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env node
2
+ // Base-985161 encoder/decoder (ES module + simple CLI)
3
+ // Radix: 985,161 (not a power of two)
4
+ // Alphabet: U+10000 .. U+10000+985160 (avoids surrogates)
5
+ // Method: big-integer base conversion (256 <-> 985,161) with leading-zero preservation
6
+
7
+ export const BASE = 985161;
8
+ export const CP_START = 0x10000;
9
+ export const CP_END = CP_START + BASE - 1;
10
+
11
+ export function valToChar(v){
12
+ if (v < 0 || v >= BASE) throw new RangeError('digit out of range');
13
+ return String.fromCodePoint(CP_START + v);
14
+ }
15
+ export function charToVal(ch){
16
+ const cp = ch.codePointAt(0);
17
+ if (cp < CP_START || cp > CP_END) throw new Error(`Invalid Base-985161 character U+${cp.toString(16).toUpperCase()}`);
18
+ return cp - CP_START;
19
+ }
20
+
21
+ // Divide big-int represented as digits[] (baseFrom, MSB-first) by divisor; return [quotientDigits, remainder]
22
+ function divmodNumber(digits, baseFrom, divisor){
23
+ const q = [];
24
+ let rem = 0;
25
+ for (let i=0;i<digits.length;i++){
26
+ const acc = rem * baseFrom + digits[i];
27
+ const d = Math.floor(acc / divisor);
28
+ rem = acc % divisor;
29
+ if (q.length || d !== 0) q.push(d);
30
+ }
31
+ return [q, rem];
32
+ }
33
+
34
+ export function encode(bytes){
35
+ if (!bytes || bytes.length === 0) return valToChar(0);
36
+
37
+ // Count leading zero bytes
38
+ let zeros = 0; while (zeros < bytes.length && bytes[zeros] === 0) zeros++;
39
+
40
+ let digits256 = Array.from(bytes); // MSB-first
41
+ const outVals = [];
42
+ while (digits256.length){
43
+ const [q, rem] = divmodNumber(digits256, 256, BASE);
44
+ outVals.push(rem);
45
+ digits256 = q;
46
+ }
47
+ // Add markers for leading zero bytes
48
+ for (let i=0;i<zeros;i++) outVals.push(0);
49
+ outVals.reverse();
50
+ return outVals.map(valToChar).join('');
51
+ }
52
+
53
+ export function decode(text){
54
+ if (!text || text.length === 0) return new Uint8Array();
55
+ const digitsB = [];
56
+ for (let i=0;i<text.length;){
57
+ const cp = text.codePointAt(i);
58
+ i += (cp > 0xFFFF ? 2 : 1);
59
+ if (cp < CP_START || cp > CP_END) throw new Error(`Invalid Base-985161 digit U+${cp.toString(16).toUpperCase()}`);
60
+ digitsB.push(cp - CP_START);
61
+ }
62
+ // Count leading zero-digits
63
+ let zeros = 0; for (const v of digitsB){ if (v===0) zeros++; else break; }
64
+
65
+ const out = [];
66
+ let arr = digitsB.slice();
67
+ while (arr.length){
68
+ const [q, rem] = divmodNumber(arr, BASE, 256);
69
+ out.push(rem);
70
+ arr = q;
71
+ }
72
+ for (let i=0;i<zeros;i++) out.push(0);
73
+ out.reverse();
74
+ return new Uint8Array(out);
75
+ }
76
+
77
+ // -------------- CLI (Node) --------------
78
+ if (typeof process !== 'undefined' && import.meta.url === `file://${process.argv[1]}`){
79
+ const fs = await import('node:fs');
80
+ const args = process.argv.slice(2);
81
+ if (args.length < 1 || !['enc','dec'].includes(args[0])){
82
+ console.error('Usage: node base985161.js enc|dec [infile|-] [outfile|-]');
83
+ process.exit(2);
84
+ }
85
+ const mode = args[0];
86
+ const inf = args[1] ?? '-';
87
+ const outf = args[2] ?? '-';
88
+
89
+ if (mode === 'enc'){
90
+ const data = inf === '-' ? await readStdinBin() : fs.readFileSync(inf);
91
+ const text = encode(new Uint8Array(data));
92
+ if (outf === '-') process.stdout.write(text);
93
+ else fs.writeFileSync(outf, text, 'utf8');
94
+ } else {
95
+ const text = inf === '-' ? await readStdinTxt() : fs.readFileSync(inf, 'utf8');
96
+ const bytes = decode(text);
97
+ if (outf === '-') process.stdout.write(Buffer.from(bytes));
98
+ else fs.writeFileSync(outf, Buffer.from(bytes));
99
+ }
100
+ }
101
+
102
+ async function readStdinBin(){ const chunks=[]; for await (const c of process.stdin) chunks.push(c); return Buffer.concat(chunks); }
103
+ async function readStdinTxt(){ const buf = await readStdinBin(); return buf.toString('utf8'); }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "base985161",
3
+ "version": "0.1.0",
4
+ "description": "Binary-to-text encoding using a 985,161-symbol Unicode alphabet (U+10000..).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/NoahenVic/BASE985161.git"
9
+ },
10
+ "homepage": "https://github.com/NoahenVic/BASE985161#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/NoahenVic/BASE985161/issues"
13
+ },
14
+ "type": "module",
15
+ "main": "./base985161.js",
16
+ "exports": {
17
+ ".": "./base985161.js"
18
+ },
19
+ "bin": {
20
+ "base985161": "./base985161.js"
21
+ },
22
+ "files": [
23
+ "base985161.js",
24
+ "README.md",
25
+ "LICENSE"
26
+ ],
27
+ "keywords": [
28
+ "base",
29
+ "encoding",
30
+ "unicode",
31
+ "binary",
32
+ "bigint"
33
+ ],
34
+ "engines": {
35
+ "node": ">=18"
36
+ }
37
+ }