Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/binary-person/rammerhead/llms.txt

Use this file to discover all available pages before exploring further.

StrShuffler encodes and decodes URL strings using a per-session character dictionary. Each session generates a unique shuffled mapping of StrShuffler.baseDictionary, so the same URL produces different ciphertext across sessions. Shuffled strings are always prefixed with _rhs so the proxy can detect whether a URL has already been encoded.

Constructor

new StrShuffler(dictionary?)
dictionary
string
A 64-character permutation of StrShuffler.baseDictionary. When omitted, a random permutation is generated by calling StrShuffler.generateDictionary().
const StrShuffler = require('./src/util/StrShuffler');

// Random dictionary (typical per-session use)
const shuffler = new StrShuffler();

// Fixed dictionary (e.g. restored from a stored session)
const shuffler2 = new StrShuffler('nQ3T8ZxR...'); // 64-char permutation

Instance methods

shuffle(str)

Encodes a plain string. Returns the shuffled string prefixed with _rhs.
shuffle(str: string): string
If str already starts with _rhs, it is returned unchanged — calling shuffle on an already-shuffled string is a no-op. Algorithm (from source):
shuffle(str) {
    if (str.startsWith(shuffledIndicator)) {
        return str;
    }
    let shuffledStr = '';
    for (let i = 0; i < str.length; i++) {
        const char = str.charAt(i);
        const idx = baseDictionary.indexOf(char);
        if (char === '%' && str.length - i >= 3) {
            // Percent-encoded sequences (%XX) pass through unmodified
            shuffledStr += char;
            shuffledStr += str.charAt(++i);
            shuffledStr += str.charAt(++i);
        } else if (idx === -1) {
            // Characters outside baseDictionary pass through unmodified
            shuffledStr += char;
        } else {
            // Position-dependent substitution
            shuffledStr += this.dictionary.charAt(mod(idx + i, baseDictionary.length));
        }
    }
    return shuffledIndicator + shuffledStr;
}
Percent-encoded sequences such as %20 or %2F are passed through without shuffling. This preserves URL validity for characters that must remain percent-encoded.

unshuffle(str)

Decodes a shuffled string back to the original. Returns the original string without the _rhs prefix.
unshuffle(str: string): string
If str does not start with _rhs, it is returned unchanged. Algorithm (from source):
unshuffle(str) {
    if (!str.startsWith(shuffledIndicator)) {
        return str;
    }
    str = str.slice(shuffledIndicator.length);

    let unshuffledStr = '';
    for (let i = 0; i < str.length; i++) {
        const char = str.charAt(i);
        const idx = this.dictionary.indexOf(char);
        if (char === '%' && str.length - i >= 3) {
            unshuffledStr += char;
            unshuffledStr += str.charAt(++i);
            unshuffledStr += str.charAt(++i);
        } else if (idx === -1) {
            unshuffledStr += char;
        } else {
            unshuffledStr += baseDictionary.charAt(mod(idx - i, baseDictionary.length));
        }
    }
    return unshuffledStr;
}

Static methods

StrShuffler.generateDictionary()

Generates a random 64-character permutation of baseDictionary suitable for use as a shuffle dictionary.
StrShuffler.generateDictionary(): string
const dict = StrShuffler.generateDictionary();
// e.g. 'q7Km3T...Z' — 64 chars, unique ordering every call
This is called automatically when you construct a StrShuffler without passing a dictionary. Each session stores its own generated dictionary so that URLs can be decoded later.

Static properties

StrShuffler.baseDictionary

The fixed 64-character alphabet that all dictionaries are permutations of.
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz~-'
Characters outside this set (including /, _, and any non-ASCII characters) are passed through unchanged by both shuffle and unshuffle.
/ and _ are intentionally excluded from baseDictionary. / must remain literal for URL path parsing; _ is reserved as part of the _rhs shuffled indicator prefix.

StrShuffler.shuffledIndicator

The prefix prepended to every shuffled string: '_rhs'. The proxy checks for this prefix to determine whether a URL path segment has already been encoded.

Example

const StrShuffler = require('./src/util/StrShuffler');

const shuffler = new StrShuffler();

const original = 'https://example.com/search?q=hello world';
const shuffled = shuffler.shuffle(original);

console.log(shuffled);
// '_rhs...' — starts with shuffled indicator, content varies by session

const restored = shuffler.unshuffle(shuffled);
console.log(restored === original); // true
Idempotency checks:
// shuffle is idempotent when already shuffled
const double = shuffler.shuffle(shuffled);
console.log(double === shuffled); // true

// unshuffle is idempotent on plain strings
const plain = shuffler.unshuffle('https://example.com');
console.log(plain === 'https://example.com'); // true

Build docs developers (and LLMs) love