Created
October 17, 2019 12:45
-
-
Save glafarge/6d04d177b04d0d47d9139735f4615541 to your computer and use it in GitHub Desktop.
Hide text in string using unicode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Code from https://syllab.fr/projets/experiments/wutf/ */ | |
var placeholders = [ | |
"Hey ! What's up ?", | |
"Hello !?", | |
"Yop !", | |
"You're here ?", | |
"Got a second ?", | |
"I need you man", | |
"Plans for the week end ?", | |
"This movie is so bad", | |
"I ate too much candies", | |
"I am sick", | |
"I am soo exhausted...", | |
"please ?", | |
"what ?", | |
"Did you see Jim ?", | |
"How are you ?", | |
"I go to sleep", | |
"brb", | |
"Come on !", | |
"it's raining cows today", | |
"man its so hot", | |
"brrrr so cold", | |
"I bought a new phone", | |
"Give me a break !", | |
"can't tell", | |
"i don't know sorry", | |
"yes of course !", | |
"nope", | |
"yeah sure", | |
"no never", | |
"hey yo", | |
"call me when you got this", | |
"where are u", | |
"bar at 7 ?", | |
"did you see my phone ?", | |
"happy birthday !", | |
]; | |
var charToHex = function (c) { return c.charCodeAt(0).toString(16); }; | |
var SERROGATE_PAIR = "%uDB40"; | |
var convertChar = function (c) { return SERROGATE_PAIR + "%uDD" + charToHex(c).slice(0, 2); }; | |
var randomPlaceholder = function () { return placeholders[Math.floor(Math.random() * placeholders.length)]; }; | |
function encode(s, placeholder) { | |
//s = s.normalize('NFD').replace(/[\u0300-\u036f]/g, "") // remove diactrics | |
var chars = s.split(''); | |
if (!placeholder || placeholder.length < 2) | |
placeholder = randomPlaceholder(); | |
return unescape(placeholder[0] + chars.map(convertChar).join('') + placeholder.substr(1)); | |
} | |
function decode(s) { | |
var escaped = escape(s); | |
if (!escaped.includes(SERROGATE_PAIR)) | |
return "(this text does not seem to be encoded)"; | |
var lastSecretChar = escaped.lastIndexOf(SERROGATE_PAIR) + 2 * SERROGATE_PAIR.length; | |
return unescape(escaped.substring(1, lastSecretChar).replace(/u.{8}/g, '')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://freetools.textmagic.com/unicode-detector
https://www.soscisurvey.de/tools/view-chars.php