ctf-party 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ctf_party.rb +1 -0
- data/lib/ctf_party/hex.rb +64 -0
- data/lib/ctf_party/leet.rb +29 -0
- data/lib/ctf_party/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 588a5007de92c7e4c3fe7654f755eb9d1f9c81a738739455b3f9b89eb87ea9fa
|
4
|
+
data.tar.gz: 85bad8baf276cfa5315dc59f1804b4b21e21f46c8061d1d1bb2e5068e82167ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0894030c2104ef8cd1421c8ec579e36760af961ad8782ff9ae9cab279a2ebd62dab7e19560d68b69bfabb616f5f84020735546d1470716cea0cf1e6ba6417ff
|
7
|
+
data.tar.gz: 923114873849d37ef0a3b1f5bd4a087e1a385c95e28dcd87761ecc247f51eda936ee058a977c6b25d7c35592133e40a602e89097cea68f8f36cdd61f2759d42d
|
data/lib/ctf_party.rb
CHANGED
data/lib/ctf_party/hex.rb
CHANGED
@@ -33,6 +33,8 @@ class String
|
|
33
33
|
# string. Example of values: +0x+, +\x+.
|
34
34
|
# @option opts [Symbol] :case Char case of the ouput. Default value +:lower+.
|
35
35
|
# Other valid value +:upper+.
|
36
|
+
# @option opts [Symbol] :padding Minimum size of the hexadecimal display
|
37
|
+
# (number of characters). Eg. 10 -> 0xA or 0x0A
|
36
38
|
# @return [String] the hexadecimal encoded string
|
37
39
|
# @example
|
38
40
|
# '255'.dec2hex # => "ff"
|
@@ -40,8 +42,11 @@ class String
|
|
40
42
|
def dec2hex(opts = {})
|
41
43
|
opts[:prefix] ||= ''
|
42
44
|
opts[:case] ||= :lower
|
45
|
+
opts[:padding] ||= 1
|
43
46
|
# convert
|
44
47
|
out = to_i.to_s(16)
|
48
|
+
# padding
|
49
|
+
out = ('0' * (opts[:padding] - 1)) + out if out.size < opts[:padding]
|
45
50
|
# char case management
|
46
51
|
out = out.upcase if opts[:case] == :upper
|
47
52
|
# adding prefix must be done after case change
|
@@ -209,4 +214,63 @@ class String
|
|
209
214
|
def bin2hex!(opts = {})
|
210
215
|
replace(bin2hex(opts))
|
211
216
|
end
|
217
|
+
|
218
|
+
# Decode a hexadecimal IP string into a dotted decimal one
|
219
|
+
# @param opts [Hash] optional parameters
|
220
|
+
# @option opts [String] :prefix Prefix of the input. Default value is a void
|
221
|
+
# string. Example of values: +0x+, +\x+.
|
222
|
+
# @option opts [Symbol] :nibble Display input with high nibble first
|
223
|
+
# (+:high+ default) or low nibble first (+:low+, used on Unix +/proc/net/tcp+).
|
224
|
+
# @return [String] the dotted decimal IP
|
225
|
+
# @example
|
226
|
+
# '0100007F'.from_hexip(nibble: :low) # => "127.0.0.1"
|
227
|
+
# '0x7f000001'.from_hexip(prefix: '0x') # => "127.0.0.1"
|
228
|
+
def from_hexip(opts = {})
|
229
|
+
opts[:prefix] ||= ''
|
230
|
+
opts[:nibble] ||= :high
|
231
|
+
# remove prefix
|
232
|
+
out = sub(opts[:prefix], '')
|
233
|
+
# convert
|
234
|
+
out = out.scan(/.{2}/).map(&:hex2dec)
|
235
|
+
out = out.reverse if opts[:nibble] == :low
|
236
|
+
out.join('.')
|
237
|
+
end
|
238
|
+
|
239
|
+
# Decode a hexadecimal IP string into a dotted decimal one in place as described
|
240
|
+
# for {String#from_hexip}.
|
241
|
+
def from_hexip!(opts = {})
|
242
|
+
replace(from_hexip(opts))
|
243
|
+
end
|
244
|
+
|
245
|
+
# Encode a dotted decimal IP into a hexadecimal one
|
246
|
+
# @param opts [Hash] optional parameters
|
247
|
+
# @option opts [String] :prefix Prefix of the output. Default value is a void
|
248
|
+
# string. Example of values: +0x+, +\x+.
|
249
|
+
# @option opts [Symbol] :case Char case of the ouput. Default value +:lower+.
|
250
|
+
# Other valid value +:upper+.
|
251
|
+
# @option opts [Symbol] :nibble Display output with high nibble first
|
252
|
+
# (+:high+ default) or low nibble first (+:low+, used on Unix +/proc/net/tcp+).
|
253
|
+
# @return [String] the hexadecimal encoded IP
|
254
|
+
# @example
|
255
|
+
# '127.0.0.1'.to_hexip # => "7f000001"
|
256
|
+
# '127.0.0.1'.to_hexip(nibble: :low) # => "0100007f"
|
257
|
+
def to_hexip(opts = {})
|
258
|
+
opts[:prefix] ||= ''
|
259
|
+
opts[:case] ||= :lower
|
260
|
+
opts[:nibble] ||= :high
|
261
|
+
# convert
|
262
|
+
out = split('.').map { |x| x.dec2hex(padding: 2) }
|
263
|
+
out = out.reverse if opts[:nibble] == :low
|
264
|
+
out = out.join
|
265
|
+
# char case management
|
266
|
+
out = out.upcase if opts[:case] == :upper
|
267
|
+
# adding prefix must be done after case change
|
268
|
+
return opts[:prefix] + out
|
269
|
+
end
|
270
|
+
|
271
|
+
# Encode a dotted decimal IP into a hexadecimal one in place as described
|
272
|
+
# for {String#to_hexip}.
|
273
|
+
def to_hexip!(opts = {})
|
274
|
+
replace(to_hexip(opts))
|
275
|
+
end
|
212
276
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class String
|
4
|
+
# Transform into leet speak (l337 5p34k)
|
5
|
+
# @example
|
6
|
+
# 'The quick brown fox jumps over the lazy dog'.leet # => "7h3 qu1ck 8r0wn f0x jump5 0v3r 7h3 14zy d06"
|
7
|
+
# 'leet speak'.leet # => "1337 5p34k"
|
8
|
+
def leet
|
9
|
+
tr = {
|
10
|
+
'T' => '7',
|
11
|
+
'E' => '3',
|
12
|
+
'I' => '1',
|
13
|
+
'L' => '1',
|
14
|
+
'O' => '0',
|
15
|
+
'S' => '5',
|
16
|
+
'A' => '4',
|
17
|
+
'G' => '6',
|
18
|
+
'B' => '8'
|
19
|
+
}
|
20
|
+
tr.merge! tr.transform_keys(&:downcase)
|
21
|
+
gsub(/[#{tr.keys.join}]/i, **tr)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Transform into leet speak (l337 5p34k) in place as described
|
25
|
+
# for {String#leet}.
|
26
|
+
def leet!
|
27
|
+
replace(leet)
|
28
|
+
end
|
29
|
+
end
|
data/lib/ctf_party/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ctf-party
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre ZANNI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-skip
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,6 +155,7 @@ files:
|
|
141
155
|
- lib/ctf_party/digest.rb
|
142
156
|
- lib/ctf_party/flag.rb
|
143
157
|
- lib/ctf_party/hex.rb
|
158
|
+
- lib/ctf_party/leet.rb
|
144
159
|
- lib/ctf_party/rot.rb
|
145
160
|
- lib/ctf_party/version.rb
|
146
161
|
homepage: https://noraj.github.io/ctf-party/
|