Last active
January 1, 2016 13:19
-
-
Save st98/8149972 to your computer and use it in GitHub Desktop.
アルファベットからleetへの変換。読めないです。 http://ja.wikipedia.org/wiki/Leet
This file contains 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
(function () { | |
var root = this; | |
var leet = {}; | |
if (typeof exports !== 'undefined') { | |
if (typeof module !== 'undefined' && module.exports) { | |
exports = module.exports = leet; | |
} | |
exports.leet = leet; | |
} else { | |
root.leet = leet; | |
} | |
var randint = function (a) { | |
return Math.random() * a | 0; | |
}; | |
var leetMap = { | |
a: ['4', '@', '/\\'], | |
b: ['|3', '/3', '13'], | |
c: ['[', '<', '('], | |
d: ['|)', '|>', '|]', '[)'], | |
e: ['3'], | |
f: ['|=', '/='], | |
g: ['6', '9'], | |
h: ['|-|', '}-{'], | |
i: ['1', '!', '|'], | |
j: ['_|', '_/'], | |
k: ['|<', ']<'], | |
l: ['|_'], | |
m: ['/\\/\\', '(V)', '|v|'], | |
n: ['|\\|', '/\\/'], | |
o: ['0', '()'], | |
p: ['|*'], | |
q: ['0_', '()_'], | |
r: ['|2'], | |
s: ['5', '$'], | |
t: ['+', '-|-'], | |
u: ['|_|', '(_)'], | |
v: ['|/', '\\/'], | |
w: ['\\/\\/'], | |
x: ['><', ')(', '}{'], | |
y: ['\\|/', '7'], | |
z: ['2', '7_'] | |
}; | |
leet.encode = function (str) { | |
var i, len, ch, map, | |
result = ''; | |
for (i = 0, len = str.length; i < len; i++) { | |
ch = str[i].toLowerCase(); | |
if (ch in leetMap) { | |
map = leetMap[ch]; | |
result += map[randint(map.length)]; | |
} else { | |
result += ch; | |
} | |
} | |
return result; | |
}; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment