Skip to content

Commit 7b75f33

Browse files
peachbitsclaude
andcommitted
Add asObfuscatedString cleaner
Decodes strings stored as arrays of XOR-masked char codes, with a scripts/obfuscateString.ts helper to generate the arrays for env.json. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 32ac597 commit 7b75f33

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

scripts/obfuscateString.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Generates the obfuscated char-code array to paste into env.json for
2+
// fields cleaned by asObfuscatedString.
3+
//
4+
// Usage:
5+
// node -r sucrase/register scripts/obfuscateString.ts <plaintext...>
6+
7+
import { wasObfuscatedString } from '../src/util/cleaners/asObfuscatedString'
8+
9+
const plaintext = process.argv.slice(2).join(' ')
10+
11+
if (plaintext === '') {
12+
console.error('Usage: obfuscateString.ts <plaintext>')
13+
process.exit(1)
14+
}
15+
16+
console.log(JSON.stringify(wasObfuscatedString(plaintext)))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { asArray, asCodec, asNumber, uncleaner } from 'cleaners'
2+
3+
// XOR mask applied to each char code. Not a secret.
4+
const MASK = 0x5a
5+
6+
/**
7+
* Decodes a string stored as an array of XOR-masked char codes,
8+
* e.g. "hi" <-> [0x32, 0x33]. Use `wasObfuscatedString` or
9+
* scripts/obfuscateString.ts to generate the array.
10+
*/
11+
export const asObfuscatedString = asCodec<string>(
12+
raw =>
13+
asArray(asNumber)(raw)
14+
.map(code => String.fromCharCode(code ^ MASK))
15+
.join(''),
16+
clean => clean.split('').map(ch => ch.charCodeAt(0) ^ MASK)
17+
)
18+
19+
export const wasObfuscatedString = uncleaner(asObfuscatedString)

0 commit comments

Comments
 (0)