Skip to content

Instantly share code, notes, and snippets.

@ipetropolsky
Last active April 4, 2025 15:20
Show Gist options
  • Select an option

  • Save ipetropolsky/e711303b9f6fb7a169d51988006f18bf to your computer and use it in GitHub Desktop.

Select an option

Save ipetropolsky/e711303b9f6fb7a169d51988006f18bf to your computer and use it in GitHub Desktop.
Experiment: encode string against text analyzers
const encode = (str, debug) => str.split(' ').map((word) => {
const cleanWord = word.replace(/^[^а-яa-z0-9]*|[^а-яa-z0-9]*$/uig, '');
if (cleanWord.length <= 3) {
debug && console.log(`${word} → ${cleanWord}: skip`);
return word;
}
const fixedChars = cleanWord.length > 12 ? 4 : (cleanWord.length > 9 ? 3 : (cleanWord.length > 6 ? 2 : 1));
const head = word.replace(new RegExp(`^([^а-яa-z0-9]*[а-яa-z0-9]{${fixedChars}}).+$`, 'ui'), '$1');
const tail = word.replace(new RegExp(`^.+([а-яa-z0-9]{${fixedChars}}[^а-яa-z0-9]*)$`, 'ui'), '$1');
const middle = word.slice(head.length, word.length - tail.length);
debug && console.log(`${word} → ${cleanWord} (${fixedChars}): ${head}|${middle}|${tail}`);
let middleShuffled = middle;
if (middle.length > 1) {
while (middleShuffled === middle) {
middleShuffled = middle.split('').sort( () => .5 - Math.random() ).join('');
}
}
return head + middleShuffled + tail;
}).join(' ');
// Длишнноеее жиновтое покавиачясь смторит теледпаирогоррамму!
// Чеолвек всё рнвао межот приотачть, но поксиом не нйтаи, и анатилзаор тескта нчгиео не пёйомт.
// Кждыай раз ноове предавлтсение свлоа! С уоёчтм зноакв пренаипния и днилы солва (чем длнниее, тем болшье неияеенмзмые чтсаи в нлачае и в кцное, чотбы возжомно блыо пртиачоть).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment