Skip to content

Instantly share code, notes, and snippets.

@dongho-jung
Created July 31, 2017 13:58
Show Gist options
  • Save dongho-jung/b1b097aa263575027f583f6c2c9ddd00 to your computer and use it in GitHub Desktop.
Save dongho-jung/b1b097aa263575027f583f6c2c9ddd00 to your computer and use it in GitHub Desktop.
obfuscate characters by its shape. and also supports l33t, 야민정음, else
<script>
var prob = 0.8;
String.prototype.replaceAt = function(index, character) {
return this.substr(0, index) + character + this.substr(index + 1);
}
function randomRange(n1, n2) {
return Math.floor((Math.random() * (n2 - n1 + 1)) + n1);
}
function chgchr(res, i, old, chg) {
if (Math.random() > prob && res.charAt(i) == old) {
res = res.replaceAt(i, chg[randomRange(0, chg.length - 1)]);
}
return res;
}
function chgkor(res, i, old, chg) {
var kors = res.charAt(i).toKorChars();
var kors2;
if (kors[0] == old[0] && ((old[1] == 0) ? 1 == 1 : old[1] == kors[1]) && ((old[2] == 0) ? 1 == 1 : old[2] == kors[2]) && Math.random() > prob / 2) {
if (typeof chg !== 'object') {
if (((chg.toKorChars()[2] != 0 && ((old[2] == 0) ? kors[2] == 0 : old[2] == kors[2])) || chg.toKorChars()[2] == 0)) {
kors[0] = chg.toKorChars()[0];
kors[1] = chg.toKorChars()[1];
kors[2] = (chg.toKorChars()[2] == 0 && old[2] == 0) ? kors[2] : chg.toKorChars()[2];
kors2 = ((kors[0] * 21) + kors[1]) * 28 + kors[2] + 0xAC00;
res = res.replaceAt(i, String.fromCharCode(kors2));
}
} else {
res = res.replaceAt(i, chg[randomRange(0, chg.length - 1)]);
}
}
return res;
}
String.prototype.toKorChars = function() {
var cCho = ['ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'],
cJung = ['ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ', 'ㅔ', 'ㅕ', 'ㅖ', 'ㅗ', 'ㅘ', 'ㅙ', 'ㅚ', 'ㅛ', 'ㅜ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅠ', 'ㅡ', 'ㅢ', 'ㅣ'],
cJong = ['', 'ㄱ', 'ㄲ', 'ㄳ', 'ㄴ', 'ㄵ', 'ㄶ', 'ㄷ', 'ㄹ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ', 'ㅁ', 'ㅂ', 'ㅄ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'],
cho, jung, jong;
var str = this,
cnt = str.length,
chars = [],
cCode;
for (var i = 0; i < cnt; i++) {
cCode = str.charCodeAt(i);
cCode = str.charCodeAt(i) - 0xAC00;
jong = cCode % 28; // 종성
jung = ((cCode - jong) / 28) % 21 // 중성
cho = (((cCode - jong) / 28) - jung) / 21 // 초성
chars.push(cho, jung, jong);
}
return chars;
}
function encode() {
var str = document.getElementById("myText").value;
var res = str;
var i;
var len = str.length;
var kors, kors2;
for (i = 0; i < len; i++) {
res = chgchr(res, i, '0', ['⊙', 'O', 'o', 'ㅇ', '𝙾']);
res = chgchr(res, i, '1', ['l', 'ㅣ', 'I', '①']);
res = chgchr(res, i, '2', ['z', 'Z', '𝟚', 'Ϩ', '乙', '૨', '②']);
res = chgchr(res, i, '3', ['E', '∃', 'Ʒ', 'ᴟ', '३', '③', 'ℨ', 'ȝ']);
res = chgchr(res, i, '4', ['𝑨', '𝟜', '④']);
res = chgchr(res, i, '5', ['§', 's', 'S', '⑤']);
res = chgchr(res, i, '6', ['b', '໒', 'б', '⑥']);
res = chgchr(res, i, '7', ['⑦', 'ヿ', 'Դ', 'ך', 'ߖ', '⧶']);
res = chgchr(res, i, '8', ['B', 'Ȣ', '𝟠', 'ზ', '⑧']);
res = chgchr(res, i, '9', ['g', '੧', '৭', 'q', '𝚐', '⑨']);
res = chgchr(res, i, 'a', ['@', 'A', '⍺', '𝐚', '𝑎', '𝒶', '𝕒', '𝙖', 'α', '𝝰']);
res = chgchr(res, i, 'A', ['4', 'a', '∀', '𝐀', '𝑨', '𝒜', '𝓐', '𝘈', 'ᴀ', 'ᗅ', 'Ǎ', 'Ȧ', '𝚲', '𝞚']);
res = chgchr(res, i, 'B', ['13', '8', 'b', 'ℬ', '𝐁', '𝓑', '𝔅', '𝔹', '𝖡', 'Β', '𝛃', '𝜷', 'ჩ']);
res = chgchr(res, i, 'b', ['𝕓', '𝚋', '♭', 'Ь', '6', 'B']);
res = chgchr(res, i, 'c', ['(', 'C', '⊂', '𝐜', '𝕔', '𝔠', '𝓬', 'ϲ', 'с']);
res = chgchr(res, i, 'C', ['(', 'c', '⊂', 'ℂ', '𝐂', '𝒞', '𝗖', 'С', 'Ҫ', '𝘊']);
res = chgchr(res, i, 'd', ['D', '𝒹', '𝕕', 'ᑯ']);
res = chgchr(res, i, 'D', ['1)', 'I)', '𝒟', '𝕯', '𝔇', '⫐', 'ᗪ', 'Ð', 'd', 'ƿ', 'Ƿ']);
res = chgchr(res, i, 'e', ['3', 'E', '𝒆', '𝓮', '𝕖', 'ᘓ', 'ℯ']);
res = chgchr(res, i, 'E', ['3', 'e', '∃', '∈', 'ㅌ', '𝙴', '𝓔', '𝔈', '𝗘', '𝞔', 'Ĕ', 'Ɇ']);
res = chgchr(res, i, 'f', ['F', '𝐟', '𝔣', '𝙛', '𝕗']);
res = chgchr(res, i, 'F', ['ℱ', '𝓕', '𝑭', 'f', 'Ϝ', ]);
res = chgchr(res, i, 'g', ['ℊ', '𝓰', '𝕘', '𝗀', 'ᶃ', 'G', '9']);
res = chgchr(res, i, 'G', ['𝒢', '𝔾', 'Ǧ', 'g']);
res = chgchr(res, i, 'h', ['ℎ', '𝓱', '𝔥', '𝕙', 'ћ', 'H', 'Ⴙ']);
res = chgchr(res, i, 'H', ['ℋ', 'ℍ', '𝓗', '𝞖', 'Ӈ', 'h']);
res = chgchr(res, i, 'l', ['1', 'L', 'ㅣ', '|', '│', '┃', '╿', '╽']);
res = chgchr(res, i, 'i', ['!', '1', 'ㅣ', '|', '│', '┃']);
res = chgchr(res, i, 'j', ['𝒿', '𝕛', '𝙟', '𝚓', 'J']);
res = chgchr(res, i, 'J', ['𝑱', '𝓙', '𝕁', '𝙹', 'յ', 'j']);
res = chgchr(res, i, 'k', ['𝒌', '𝕜', '𝛋', 'K']);
res = chgchr(res, i, 'K', ['𝒦', '𝕂', '𝞙', 'Ⱪ', 'k']);
res = chgchr(res, i, 'l', ['|', '│', '𝟭', '𝒍', 'ℓ', '𝚕']);
res = chgchr(res, i, 'L', ['Ⅼ', 'ℒ', '𝓛', '𝕃', 'ㄴ', '∟', ' ᥨ', '⎿']);
res = chgchr(res, i, 'm', ['rn', 'nn', 'M', 'ጦ', '⩋', '⫛', '₥', 'ጠ', 'ᘻ', 'ന', 'ᗰ', '𝘮', 'ጡ']);
res = chgchr(res, i, 'M', ['|\/|', 'lVl', '𝕸', '𝓜', 'Ϻ', '|V|', 'ᗰ', 'Ϻ', 'm', '𝕄', '𝗠']);
res = chgchr(res, i, 'n', ['η', '𝜂', '𝐧', '𝑛', '𝒏', '𝓃', '𝓷', '𝔫', '𝕟', '𝖓', '𝗻', 'ռ', 'N']);
res = chgchr(res, i, 'N', ['N', 'ℕ', '𝑵', '𝓝', '𝗡', '𝜨', 'и', 'И', 'n']);
res = chgchr(res, i, 'o', ['0', 'O', 'ㅇ', '○', '●', '◎', '()', '௦', '‎٥', '๐', '૦', ' 𝒐', '𝙤', 'ᴑ', 'ο', 'ه‎', '〇', '𝟎', 'ø']);
res = chgchr(res, i, 'O', ['0', 'o', 'ㅇ', '○', '●', '◎', '()', '௦', '‎٥', '๐', '૦', ' 𝒐', '𝙤', 'ᴑ', 'ο', 'ه‎', '〇', '𝟎', 'ø']);
res = chgchr(res, i, 'p', ['⍴', '𝓅', 'P', '𝕡', '𝖕', ' 𝛒']);
res = chgchr(res, i, 'P', ['p', 'ℙ', '𝓟', 'P', '𝙿']);
res = chgchr(res, i, 'q', ['𝓆', '𝕢', 'Q', '𝖖', 'զ']);
res = chgchr(res, i, 'Q', ['ℚ', 'q', '𝑸', '𝒬', '𝖰', 'ⵕ']);
res = chgchr(res, i, 'r', ['𝓇', 'R', '𝕣', '𝙧', 'г']);
res = chgchr(res, i, 'R', ['ℛ', 'r', 'ℝ', '𝕽']);
res = chgchr(res, i, 's', ['5', 'S', '$', '§', '𝓢', '𝕊']);
res = chgchr(res, i, 'S', ['5', 's', '$', '§', '𝓢', '𝕊']);
res = chgchr(res, i, 't', ['𝕥', 'T', '𝖙']);
res = chgchr(res, i, 'T', ['†', '𝒯', 't', '𝚃']);
res = chgchr(res, i, 'u', ['∪', 'U', 'v', '𝐮', '𝑢', '𝒖', '𝕦', '𝘶', '𝙪', 'ꞟ', 'υ', '𝞄']);
res = chgchr(res, i, 'U', ['∪', 'u', 'V', '∪', '𝑈', '𝐔', '𝒰', '𝖀', '𝙐', '𝘜', 'Ǔ', 'ᑘ']);
res = chgchr(res, i, 'v', ['𝑣', '∨', '𝓋', '𝒗', 'ט‎', 'V', 'Ѵ']);
res = chgchr(res, i, 'V', ['v', '𝓥', '𝕍']);
res = chgchr(res, i, 'w', ['ɯ', 'vv', '𝕨', '𝔀', 'ꝡ', 'W']);
res = chgchr(res, i, 'W', ['ɯ', 'vv', '𝕨', '𝔀', 'ꝡ', 'w']);
res = chgchr(res, i, 'x', ['𝓍', '𝕩', '╳', '𝝬', 'X']);
res = chgchr(res, i, 'X', ['𝓍', '𝕩', '╳', '𝝬', 'x']);
res = chgchr(res, i, 'y', ['𝓎', '𝕪', 'γ', '𝛾', 'ყ', 'Y', '𝒚']);
res = chgchr(res, i, 'Y', ['𝐘', '𝓨', '𝕐', 'ϒ', 'ƴ', 'Ұ']);
res = chgchr(res, i, 'z', ['2', 'Z', 'ㄹ', '𝕫', '𝔃']);
res = chgchr(res, i, 'Z', ['2', 'z', 'ㄹ', 'ℤ', 'ℤ', 'Ȥ']);
res = chgchr(res, i, '{', ['-(', '❴', '⦃']);
res = chgchr(res, i, '}', [')-', '❵']);
res = chgchr(res, i, '(', ['⊂', '〔', 'C', 'ʗ', 'ɽ', '☾', 'Ϛ']);
res = chgchr(res, i, ')', ['⊃', '〕', '﴿', 'ᑐ', '☽', '❩', 'כ', 'ᙂ']);
res = chgchr(res, i, '<', ['⧼', '❬', '〈']);
res = chgchr(res, i, '>', ['ᐳ', '⧽', '﴿']);
res = chgchr(res, i, '!', ['ǃ', '❗', 'i', 'ٳ']);
res = chgchr(res, i, '?', ['ǃ', '❗', 'i', 'ٳ']);
res = chgkor(res, i, '대'.toKorChars(), '머');
res = chgkor(res, i, '머'.toKorChars(), '대');
res = chgkor(res, i, '귀'.toKorChars(), '커');
res = chgkor(res, i, '커'.toKorChars(), '귀');
res = chgkor(res, i, '윾'.toKorChars(), '유');
res = chgkor(res, i, '유'.toKorChars(), '윾');
res = chgkor(res, i, '근'.toKorChars(), 'ㄹ');
res = chgkor(res, i, 'ㄹ'.toKorChars(), '근');
res = chgkor(res, i, '디'.toKorChars(), 'ㅁ');
res = chgkor(res, i, '댸'.toKorChars(), '며');
res = chgkor(res, i, '며'.toKorChars(), '댸');
res = chgkor(res, i, '빅'.toKorChars(), '븨');
res = chgkor(res, i, '븨'.toKorChars(), '빅');
res = chgkor(res, i, '댸'.toKorChars(), '며');
res = chgkor(res, i, '며'.toKorChars(), '댸');
res = chgkor(res, i, '왕'.toKorChars(), '앟');
res = chgkor(res, i, '앟'.toKorChars(), '왕');
res = chgkor(res, i, '익'.toKorChars(), '의');
res = chgkor(res, i, '의'.toKorChars(), '익');
res = chgkor(res, i, '억'.toKorChars(), '여');
res = chgkor(res, i, '여'.toKorChars(), '억');
res = chgkor(res, i, '임'.toKorChars(), '읜');
res = chgkor(res, i, '읜'.toKorChars(), '임');
res = chgkor(res, i, '위'.toKorChars(), '읶');
res = chgkor(res, i, '읶'.toKorChars(), '위');
res = chgkor(res, i, 'ㅁ'.toKorChars(), ['디','口','⎕','❏','囗']);
document.getElementById('myText').value = res;
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment