-
Notifications
You must be signed in to change notification settings - Fork 0
/
leeter.js
143 lines (135 loc) · 4.66 KB
/
leeter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright 2014 KOLANICH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
"use strict";
function Leeter(tbl){//<m41n cl@ss t0 1337ify t3xtz
var self=this;
this.importCTable(tbl)
function randArr(arr){
return arr[Math.floor(Math.random()*arr.length)];
}
this.replacer=function(str,offset,s) {
return randArr(self.ctable.hashtable[str].table);
};
this.wordReplacer=function(symbolsPerWord,word,offset,s) {
var syms=word.split("").sort(function() {return 0.5 - Math.random()}).filter(function(s){return self.ctable.hashtable[s]||false;});
if(!Number.isInteger(symbolsPerWord)){
symbolsPerWord=(symbolsPerWord>1?1:symbolsPerWord)*syms.length;
}
if(symbolsPerWord>syms.length)symbolsPerWord=syms.length;
for(var i=0;i<symbolsPerWord;i++){
word=word.replace(syms[i],randArr(self.ctable.hashtable[syms[i]].table));
}
return word;
};
}
/*@
d3ph4ult 7able oph r3pl4cem3n7z
p}{1r57 173m [0n7@1nz [harz phor r3p1@[3m3n7
*/
Leeter.prototype.defaultCTable=[
["aаAА","4","@"],
["Бб","6","5"],
["BвВb","8","|3","฿"],
["CС","{","("],
["cс","["],
["Dd","|}","|]","|)","I>","[)"],
["дД","6"],
["EeеЕзЗ","3"],
["F","PH","|="],
["f","ph","£"],
["Gg","6","&"],
["HнНh","|-|","}{","#"],
["Ii","|","!"],
["Jj","]","_|",")"],
["KkкК","|<","!<"],
["L","|_","2"],
["l","1"],
["MmМм","/\\/\\","/V\\","|V|"],
["Nn","|\\|","/\/"],
["иИ","|/|"],
["oOоО","()","0","[]"],
["PpрР","?","|>","|o"],
["Q","0_","()_"],
["q","<|"],
["R","|2","|?"],
["rгГTt","7"],
["sS","5","$"],
["TtтТ","7"],
["Uu","(_)","|_|"],
["юЮ","|-0"],
["vV","\\/"],
["Ww","\\/\\/","\\^/","vv","\\X/"],
["XxхХ","}{","][","><","%"],
["YyУу","'/","\\//","¥"],
["zZ","2"],
["Жж","*",">|<","}|{","]|["],
["лЛ","/\\","J|"],
["Пп","|^|","/7"],
["Фф","<|>","(|)","[|]"],
["цЦ","|_|,","LL"],
["Чч","4"],
["Шш","w","LLI"],
["Щщ","LLL"],
["ъЪ","^|o"],
["Ыы","61","6|"],
["Ьь","b","6"],
["Ээ","€","-)","3"]
];// 774|1||\|6 [()/\/\45 473 \/37'/ |]4|\|6370(_)5 ?}{07 ||\|737|\|37 3><?1()737 3|\|6||\|3 : |7 7|-|||\||<5 7}{373 |5 1457 3/\/\|>7\// |73/\/\ ||\| 4774'/
Leeter.prototype.importCTable=function(tbl){//<us3d ph0r 1mp0r71ng y0ur 0wn 748l3z 0r r3z3t1n9 t0 d3ph@u17 0n3
tbl=tbl||this.defaultCTable;
this.ctable={};
this.ctable.objs=[];
this.ctable.hashtable={};
var len=tbl.length;
for(var i=0;i<len;i++){
var obj={};
obj.table=tbl[i];
var marker=obj.table.splice(0,1)[0];
obj.rx=new RegExp("["+marker+"]","g");
var arr=marker.split("");
for(var j=0;j<arr.length;j++)
this.ctable.hashtable[arr[j]]=obj;
this.ctable.objs.push(obj);
}
};
Leeter.prototype.makeLeet=function(text){//<uz3d for 13371ph11n9 73><7
//if the table contains unicode in non-unicode supporting environment can work fine...
var len=this.ctable.objs.length;
for(this.i=0;this.i<len;this.i++){
text=text.replace(this.ctable.objs[this.i].rx,this.replacer);
}
this.i=0;
return text;
};
Leeter.prototype.makeLeetByWords=function(text,symbolsPerWord){//<uz3d for 13371ph11n9 wh013 73><7 1im171n9 [0un7 oph 13371ph13d 5ymb01z 1n w0rdz
//if the table contains unicode in non-unicode supporting environment wont work fine - replacements with unicode characters such as currency signs can be ignored
return text.replace(/[\wа-я]+/ig,this.wordReplacer.bind(this,symbolsPerWord));
};
Leeter.prototype.testStrings=[
"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства",
"В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!",
"Съешь же ещё этих мягких французских булок, да выпей чаю",
"The quick brown fox jumps over the lazy dog",
"The five boxing wizards jump quickly."
];
Leeter.prototype.testFullReplacement=function(){
for(var p=0;p<this.testStrings.length;p++){
if(!confirm(this.makeLeet(this.testStrings[p])))break;
}
};
Leeter.prototype.testLimitedReplacement=function(){
var charsInWord=parseInt(prompt(this.makeLeet("Input count of chars to be replaced in each word")));
for(var p=0;p<this.testStrings.length;p++){
if(!confirm(this.makeLeetByWords(this.testStrings[p],charsInWord)))break;
}
};