leet 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/bin/leet +11 -6
- data/lib/leet/leet.rb +62 -2
- data/lib/leet/leets.yml +1 -17
- data/lib/leet/version.rb +1 -1
- data/spec/leet_spec.rb +30 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19ac0dee85cd357d1cbf39313550ac8255aa39a3
|
4
|
+
data.tar.gz: 416352991110d5b80b0c56d09762d15b43308d9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6de0366999bad392bdca634c5a9c0a6f57aa59a5ae62a4e87e7be9842cd4b3bf64b01517974f60ed4f7afc00f91f0f062133e5c2cdfcc800557201c2ecf57f59
|
7
|
+
data.tar.gz: f45931d0e4930b5debdf5b11c96ee97d3a51dca2526e2086396007d7102ca0af5c5199d3f66d0a1e17d966289b71319ff64d581c1a178d6a6b2ee58f5dde0d70
|
data/README.md
CHANGED
@@ -18,6 +18,9 @@ gem install leet
|
|
18
18
|
```sh
|
19
19
|
$ leet "I Love Ruby!"
|
20
20
|
$ 3y3 [_<>\|& /2(_)13\|/!
|
21
|
+
|
22
|
+
$ leet -u '3y3 [_<>\|& /2(_)13\|/!'
|
23
|
+
$ i lovg rubwi
|
21
24
|
```
|
22
25
|
## code
|
23
26
|
|
@@ -26,9 +29,13 @@ require 'leet'
|
|
26
29
|
|
27
30
|
puts "I Love Ruby!".leet
|
28
31
|
#=> j 1_p\/|=- .-L|/3`/!
|
32
|
+
|
33
|
+
puts "j 1_p\/|=- .-L|/3`/!".unleet
|
34
|
+
#=> i lo rubyi
|
35
|
+
|
29
36
|
```
|
30
37
|
|
31
38
|
# TODO
|
32
39
|
|
33
|
-
* unleet
|
40
|
+
* unleet 100% (Maybe it cannot be 100% for it like hash reverse.)
|
34
41
|
* han pinyin
|
data/bin/leet
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
$:.unshift(File.expand_path("../../lib", __FILE__))
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
require 'leet'
|
6
|
+
|
7
|
+
if ARGV.count == 1
|
8
|
+
puts ARGV[0].leet
|
9
|
+
elsif ARGV.count == 2 && ARGV[0] == "-u"
|
10
|
+
puts ARGV[1].unleet
|
11
|
+
else
|
12
|
+
puts "With the given string to leet or ."
|
13
|
+
puts 'leet usage: leet "I Love Ruby!"'
|
14
|
+
puts 'unleet usage: leet -u "| []_[]\|£ /2(_)P>Ч!"'
|
8
15
|
exit
|
9
16
|
end
|
10
|
-
|
11
|
-
puts ARGV[0].leet
|
data/lib/leet/leet.rb
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
module Leet
|
4
|
+
DEBUG = false
|
4
5
|
LEETS = YAML.load_file File.join(__dir__, 'leets.yml')
|
6
|
+
LEETS_TO_CHAR = {}
|
7
|
+
LEETS.each do |key, values|
|
8
|
+
values.each do |value|
|
9
|
+
LEETS_TO_CHAR[value] = key
|
10
|
+
end
|
11
|
+
end
|
5
12
|
|
6
13
|
def str2leet(str)
|
7
14
|
result = ""
|
@@ -15,8 +22,61 @@ module Leet
|
|
15
22
|
end
|
16
23
|
module_function :str2leet
|
17
24
|
|
18
|
-
def
|
19
|
-
|
25
|
+
def leet2char(chars)
|
26
|
+
LEETS_TO_CHAR.keys.each do |leet|
|
27
|
+
if chars == leet
|
28
|
+
puts "match #{leet} to #{LEETS_TO_CHAR[leet]}" if DEBUG
|
29
|
+
return LEETS_TO_CHAR[leet]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
module_function :leet2char
|
35
|
+
|
36
|
+
def leet2word(chars)
|
37
|
+
return "" if chars.nil? or chars.length == 0
|
38
|
+
|
39
|
+
result = ""
|
40
|
+
i = 5 # leet's max length is 5
|
41
|
+
|
42
|
+
while(i>0) do
|
43
|
+
tmp_string = chars[0,i]
|
44
|
+
c = leet2char tmp_string
|
45
|
+
if c
|
46
|
+
result << c
|
47
|
+
result << leet2word(chars[i..-1])
|
48
|
+
break
|
49
|
+
else
|
50
|
+
i -= 1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
result
|
55
|
+
end
|
56
|
+
module_function :leet2word
|
57
|
+
|
58
|
+
def leet2str(str)
|
59
|
+
result = ""
|
60
|
+
str.to_s.split(" ").each do |word|
|
61
|
+
result << leet2word(word)
|
62
|
+
result << " "
|
63
|
+
end
|
64
|
+
# result = ""
|
65
|
+
# tmp_string = ""
|
66
|
+
# str.to_s.split("").each_with_index do |char, index|
|
67
|
+
# if char == ' '
|
68
|
+
# result << ' '
|
69
|
+
# tmp_string = ""
|
70
|
+
# else
|
71
|
+
# tmp_string << char
|
72
|
+
# c = leet2char tmp_string
|
73
|
+
# if c
|
74
|
+
# result << c
|
75
|
+
# tmp_string = ''
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
result.strip
|
20
80
|
end
|
21
81
|
module_function :leet2str
|
22
82
|
end
|
data/lib/leet/leets.yml
CHANGED
@@ -33,18 +33,14 @@ d:
|
|
33
33
|
- ')'
|
34
34
|
- '|)'
|
35
35
|
- '(|'
|
36
|
-
- '|o'
|
37
36
|
- '[)'
|
38
37
|
- 'I>'
|
39
|
-
- '|>'
|
40
|
-
- ' ?'
|
41
38
|
- 'T)'
|
42
39
|
- 'I7'
|
43
40
|
- 'cl'
|
44
41
|
|
45
42
|
e:
|
46
43
|
- '3'
|
47
|
-
- '&'
|
48
44
|
- '£'
|
49
45
|
- '€'
|
50
46
|
- 'ë'
|
@@ -57,7 +53,6 @@ f:
|
|
57
53
|
- '|#'
|
58
54
|
- 'ph'
|
59
55
|
- '/='
|
60
|
-
- 'v'
|
61
56
|
|
62
57
|
g:
|
63
58
|
- '6'
|
@@ -83,12 +78,10 @@ h:
|
|
83
78
|
- '|~|'
|
84
79
|
- '|-|'
|
85
80
|
- ']~['
|
86
|
-
- '
|
87
|
-
- ' !-!'
|
81
|
+
- '!-!'
|
88
82
|
- '1-1'
|
89
83
|
- '\-/'
|
90
84
|
- 'I+I'
|
91
|
-
- ' ?'
|
92
85
|
- '}-{'
|
93
86
|
|
94
87
|
i:
|
@@ -99,7 +92,6 @@ i:
|
|
99
92
|
- '|'
|
100
93
|
- 'eye'
|
101
94
|
- '3y3'
|
102
|
-
- ']['
|
103
95
|
- ']'
|
104
96
|
- '/me'
|
105
97
|
|
@@ -119,7 +111,6 @@ k:
|
|
119
111
|
- '|X'
|
120
112
|
|
121
113
|
l:
|
122
|
-
- '£'
|
123
114
|
- '1_'
|
124
115
|
- '|_'
|
125
116
|
- 'el'
|
@@ -156,7 +147,6 @@ n:
|
|
156
147
|
- '//[]'
|
157
148
|
- '/V'
|
158
149
|
- 'И'
|
159
|
-
- '^'
|
160
150
|
|
161
151
|
o:
|
162
152
|
- '0'
|
@@ -170,11 +160,9 @@ p:
|
|
170
160
|
- '|*'
|
171
161
|
- '|o'
|
172
162
|
- '|º'
|
173
|
-
- ' ?'
|
174
163
|
- '|^(o)'
|
175
164
|
- '|>'
|
176
165
|
- '|"'
|
177
|
-
- '9'
|
178
166
|
- '[]D'
|
179
167
|
- '|°'
|
180
168
|
- '|7'
|
@@ -243,7 +231,6 @@ w:
|
|
243
231
|
- '\|/'
|
244
232
|
- '\_|_/'
|
245
233
|
- '\_:_/'
|
246
|
-
- '?'
|
247
234
|
- 'uu'
|
248
235
|
- '2u'
|
249
236
|
|
@@ -253,15 +240,12 @@ x:
|
|
253
240
|
- '}{'
|
254
241
|
- 'ecks'
|
255
242
|
- '×'
|
256
|
-
- '?'
|
257
243
|
- ')('
|
258
244
|
- ']['
|
259
|
-
- '}{'
|
260
245
|
|
261
246
|
y:
|
262
247
|
- '`/'
|
263
248
|
- 'Ч'
|
264
|
-
- '\|/'
|
265
249
|
- '¥'
|
266
250
|
|
267
251
|
z:
|
data/lib/leet/version.rb
CHANGED
data/spec/leet_spec.rb
CHANGED
@@ -2,13 +2,38 @@ require_relative '../lib/leet'
|
|
2
2
|
require_relative './spec_helper'
|
3
3
|
|
4
4
|
describe Leet do
|
5
|
-
describe '
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
describe 'leet' do
|
6
|
+
it 'leet a..z' do
|
7
|
+
('a'..'z').to_a.each do |c|
|
8
|
+
leet = c.leet
|
9
|
+
puts "#{c}: #{leet}"
|
10
10
|
expect(c).not_to eq(leet)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
14
|
+
|
15
|
+
describe 'unleet' do
|
16
|
+
it 'unleet sample' do
|
17
|
+
expect("| []_[]\|£ /2(_)P>Ч!".unleet).to eq("i love ruby!")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'leets.yml' do
|
22
|
+
it 'LEETS values count should equal to LEETS_TO_CHAR keys count' do
|
23
|
+
expect(Leet::LEETS.values.flatten.count).to eq(Leet::LEETS_TO_CHAR.keys.count)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'one leet to one char' do
|
27
|
+
leets_to_char = {}
|
28
|
+
Leet::LEETS.each do |key, values|
|
29
|
+
values.each do |value|
|
30
|
+
if leets_to_char.has_key? value
|
31
|
+
raise "!!! #{value} duplicate on #{key} and #{leets_to_char[value]}"
|
32
|
+
else
|
33
|
+
leets_to_char[value] = key
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
14
39
|
end
|