ctf-party 1.0.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +2 -1
  3. data/bin/ctf_party_console +0 -0
  4. data/lib/ctf_party.rb +2 -0
  5. data/lib/ctf_party/base64.rb +6 -13
  6. data/lib/ctf_party/case.rb +35 -0
  7. data/lib/ctf_party/digest.rb +12 -10
  8. data/lib/ctf_party/flag.rb +1 -5
  9. data/lib/ctf_party/hex.rb +212 -0
  10. data/lib/ctf_party/rot.rb +2 -2
  11. data/lib/ctf_party/version.rb +1 -1
  12. metadata +28 -73
  13. data/.rubocop.yml +0 -29
  14. data/.yardopts +0 -4
  15. data/.yardopts-dev +0 -6
  16. data/Gemfile +0 -6
  17. data/Gemfile.lock +0 -52
  18. data/README.md +0 -57
  19. data/Rakefile +0 -11
  20. data/bin/ctf_party_setup +0 -6
  21. data/docs/.nojekyll +0 -0
  22. data/docs/About.md +0 -5
  23. data/docs/CHANGELOG.md +0 -5
  24. data/docs/README.md +0 -52
  25. data/docs/_coverpage.md +0 -10
  26. data/docs/_media/logo.png +0 -0
  27. data/docs/_navbar.md +0 -3
  28. data/docs/_sidebar.md +0 -13
  29. data/docs/index.html +0 -31
  30. data/docs/pages/documentation.md +0 -30
  31. data/docs/pages/install.md +0 -84
  32. data/docs/pages/publishing.md +0 -39
  33. data/docs/pages/quick-start.md +0 -23
  34. data/docs/pages/usage.md +0 -61
  35. data/docs/vendor/docsify.js +0 -1
  36. data/docs/vendor/plugins/emoji.min.js +0 -1
  37. data/docs/vendor/plugins/search.min.js +0 -1
  38. data/docs/vendor/prismjs/components/prism-ruby.min.js +0 -1
  39. data/docs/vendor/themes/vue.css +0 -1
  40. data/docs/yard/String.html +0 -2909
  41. data/docs/yard/Version.html +0 -121
  42. data/docs/yard/_index.html +0 -123
  43. data/docs/yard/class_list.html +0 -51
  44. data/docs/yard/css/common.css +0 -1
  45. data/docs/yard/css/full_list.css +0 -58
  46. data/docs/yard/css/style.css +0 -496
  47. data/docs/yard/file.LICENSE.html +0 -70
  48. data/docs/yard/file.README.html +0 -124
  49. data/docs/yard/file_list.html +0 -61
  50. data/docs/yard/frames.html +0 -17
  51. data/docs/yard/index.html +0 -124
  52. data/docs/yard/js/app.js +0 -303
  53. data/docs/yard/js/full_list.js +0 -216
  54. data/docs/yard/js/jquery.js +0 -4
  55. data/docs/yard/method_list.html +0 -275
  56. data/docs/yard/top-level-namespace.html +0 -112
  57. data/test/test_string.rb +0 -134
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c9bbfee898723defee53d242711a127753c3bef4f6828477d4f686e4487713e
4
- data.tar.gz: 69f0e9e1e7bb5fd27dcbd37b2c86d8ce6514307f3eb413d196e89822ad8e6e6e
3
+ metadata.gz: a1bc032bfe7236e135eccd26e75a67d6b178b2486b1610741017d61e6cd78c16
4
+ data.tar.gz: 40ec92a25213dc22154190cf2e726ad87ce693e9f2e283c7b544c1e378634869
5
5
  SHA512:
6
- metadata.gz: 58b042d0a45a771eb5889438497c15c8126039016b70362d0dcffd58b41a35442735351a14d099744603a778a3dc9684e76a1f72334adca4b2124552205e0b2f
7
- data.tar.gz: 35c6e42f0c33448bba0acfd9ac126221ac557cfd47f4042edf844aed7bccf0272aaba52e38ee184959dbe0c56630f10c08575b6f0be25e9eeb3bd2a21ac02537
6
+ metadata.gz: 6d2fb3942843aafde1c157ec4ee598cdfdb9970a178f66fb291964d3f5e867838c94683068ab4a8e6bc02318e3e56336f3832315f7e0a8e01581649354cd7840
7
+ data.tar.gz: 91709a253527bec78f79cb45c5bf0611f09262dc0c25beacb0a153c534f4f4042e18977a3c020f961c7786551017a056b423114f72ee2ba7a794c09d8f5378ed
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 Alexandre ZANNI
3
+ Copyright (c) 2020-2020 Alexandre ZANNI
4
+ Copyright (c) 2019-2020 Alexandre ZANNI at Orange Cyberdefense
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
File without changes
@@ -5,3 +5,5 @@ require 'ctf_party/base64'
5
5
  require 'ctf_party/rot'
6
6
  require 'ctf_party/digest'
7
7
  require 'ctf_party/flag'
8
+ require 'ctf_party/hex'
9
+ require 'ctf_party/case'
@@ -27,11 +27,7 @@ class String
27
27
  # myStr.to_b64! # => nil
28
28
  # myStr # => "UnVieQ=="
29
29
  def to_b64!(opts = {})
30
- opts[:mode] ||= :strict
31
- replace(to_b64) if opts[:mode] == :strict ||
32
- opts[:mode] == :rfc4648
33
- replace(to_b64(mode: :rfc2045)) if opts[:mode] == :rfc2045
34
- replace(to_b64(mode: :urlsafe)) if opts[:mode] == :urlsafe
30
+ replace(to_b64(opts))
35
31
  end
36
32
 
37
33
  # Decode the string from base64
@@ -57,11 +53,7 @@ class String
57
53
  # a.from_b64! # => nil
58
54
  # a # => "Hello world!"
59
55
  def from_b64!(opts = {})
60
- opts[:mode] ||= :strict
61
- replace(from_b64) if opts[:mode] == :strict ||
62
- opts[:mode] == :rfc4648
63
- replace(from_b64(mode: :rfc2045)) if opts[:mode] == :rfc2045
64
- replace(from_b64(mode: :urlsafe)) if opts[:mode] == :urlsafe
56
+ replace(from_b64(opts))
65
57
  end
66
58
 
67
59
  # Is the string encoded in base64?
@@ -82,14 +74,15 @@ class String
82
74
  (?:[a-zA-Z0-9+/]{2}==)|(?:[a-zA-Z0-9+/]{1}===))\Z}xn
83
75
  reg3 = /\A(?:[a-zA-Z0-9\-_]{4})*(?:|(?:[a-zA-Z0-9\-_]{3}=)|
84
76
  (?:[a-zA-Z0-9\-_]{2}==)|(?:[a-zA-Z0-9\-_]{1}===))\Z/xn
85
- if opts[:mode] == :strict || opts[:mode] == :rfc4648
77
+ case opts[:mode]
78
+ when :strict, :rfc4648
86
79
  b64 = true if reg1.match?(self)
87
- elsif opts[:mode] == :rfc2045
80
+ when :rfc2045
88
81
  b64 = true
89
82
  split("\n").each do |s|
90
83
  b64 = false unless reg1.match?(s)
91
84
  end
92
- elsif opts[:mode] == :urlsafe
85
+ when :urlsafe
93
86
  b64 = true if reg3.match?(self)
94
87
  else
95
88
  raise ArgumentError 'Wrong mode'
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ # Change the case of characters randomly
5
+ # @return [String] the case modified string
6
+ # @example
7
+ # 'SELECT * FROM'.randomcase # => "SElECt * frOm"
8
+ # 'SELECT * FROM'.randomcase # => "selECT * FROm"
9
+ def randomcase
10
+ chars.map { |c| rand(0..1).zero? ? c.downcase : c.upcase }.join
11
+ end
12
+
13
+ # Change the case of characters randomly in place as described for
14
+ # {String#randomcase}.
15
+ def randomcase!
16
+ replace(randomcase)
17
+ end
18
+
19
+ # Change one characte on two upcase and the other downcase
20
+ # @param shift [Integer] 0: 1st character will be downcase, 1: 1st character
21
+ # will be upcase
22
+ # @return [String] the case modified string
23
+ # @example
24
+ # 'SELECT * FROM'.alternatecase # => "sElEcT * FrOm"
25
+ # 'SELECT * FROM'.alternatecase(1) # => "SeLeCt * fRoM"
26
+ def alternatecase(shift = 0)
27
+ chars.each_with_index.map { |c, i| (i + shift).even? ? c.downcase : c.upcase }.join
28
+ end
29
+
30
+ # Change one characte on two upcase and the other downcase in place as
31
+ # described for {String#alternatecase}.
32
+ def alternatecase!(shift = 0)
33
+ replace(alternatecase(shift))
34
+ end
35
+ end
@@ -13,7 +13,7 @@ class String
13
13
  Digest::MD5.hexdigest self
14
14
  end
15
15
 
16
- # Calculate the md5 hash of the string in place as described for {#md5}.
16
+ # Calculate the md5 hash of the string in place as described for {String#md5}.
17
17
  # @example
18
18
  # a = '\o/' # => "\\o/"
19
19
  # a.md5! # => "881419964e480e66162da521ccc25ebf"
@@ -31,7 +31,8 @@ class String
31
31
  Digest::SHA1.hexdigest self
32
32
  end
33
33
 
34
- # Calculate the sha1 hash of the string in place as described for {#sha1}.
34
+ # Calculate the sha1 hash of the string in place as described for
35
+ # {String#sha1}.
35
36
  # @example
36
37
  # bob = 'alice' # => "alice"
37
38
  # bob.sha1! # => "522b276a356bdf39013dfabea2cd43e141ecc9e8"
@@ -55,7 +56,8 @@ class String
55
56
  Digest::SHA2.new(opts[:bitlen]).hexdigest self
56
57
  end
57
58
 
58
- # Calculate the sha2 hash of the string in place as described for {#sha2}.
59
+ # Calculate the sha2 hash of the string in place as described for
60
+ # {String#sha2}.
59
61
  # @example
60
62
  # th = 'try harder' # => "try harder"
61
63
  # th.sha2!(bitlen: 384) # => "bb7f60b9562a19c3a83c23791440af11591c42ede9..."
@@ -64,32 +66,32 @@ class String
64
66
  replace(sha2(opts))
65
67
  end
66
68
 
67
- # Alias for {#sha2} with default value ( +sha2(bitlen: 256)+ ).
69
+ # Alias for {String#sha2} with default value ( +sha2(bitlen: 256)+ ).
68
70
  def sha2_256
69
71
  sha2
70
72
  end
71
73
 
72
- # Alias for {#sha2!} with default value ( +sha2!(bitlen: 256)+ ).
74
+ # Alias for {String#sha2!} with default value ( +sha2!(bitlen: 256)+ ).
73
75
  def sha2_256!
74
76
  replace(sha2)
75
77
  end
76
78
 
77
- # Alias for {#sha2} with default value ( +sha2(bitlen: 384)+ ).
79
+ # Alias for {String#sha2} with default value ( +sha2(bitlen: 384)+ ).
78
80
  def sha2_384
79
81
  sha2(bitlen: 384)
80
82
  end
81
83
 
82
- # Alias for {#sha2!} with default value ( +sha2!(bitlen: 384)+ ).
84
+ # Alias for {String#sha2!} with default value ( +sha2!(bitlen: 384)+ ).
83
85
  def sha2_384!
84
86
  replace(sha2(bitlen: 384))
85
87
  end
86
88
 
87
- # Alias for {#sha2} with default value ( +sha2(bitlen: 512)+ ).
89
+ # Alias for {String#sha2} with default value ( +sha2(bitlen: 512)+ ).
88
90
  def sha2_512
89
91
  sha2(bitlen: 512)
90
92
  end
91
93
 
92
- # Alias for {#sha2!} with default value ( +sha2!(bitlen: 512)+ ).
94
+ # Alias for {String#sha2!} with default value ( +sha2!(bitlen: 512)+ ).
93
95
  def sha2_512!
94
96
  replace(sha2(bitlen: 512))
95
97
  end
@@ -104,7 +106,7 @@ class String
104
106
  end
105
107
 
106
108
  # Calculate the RIPEMD-160 hash of the string in place as described for
107
- # {#rmd160}.
109
+ # {String#rmd160}.
108
110
  # @example
109
111
  # pl = 'payload' # => "payload"
110
112
  # pl.rmd160! # => "3c6255c112d409dafdb84d5b0edba98dfd27b44f"
@@ -16,8 +16,6 @@ class String
16
16
  @@flag
17
17
  end
18
18
 
19
- # rubocop:disable Metrics/LineLength
20
-
21
19
  # Update the flag configuration.
22
20
  # @param hash [Hash] flag configuration
23
21
  # @option hash [String] :prefix prefix of the flag. Default: none.
@@ -40,8 +38,6 @@ class String
40
38
  @@flag.merge!(hash)
41
39
  end
42
40
 
43
- # rubocop:enable Metrics/LineLength
44
-
45
41
  # Format the current string into the configured flag format. See {.flag=}
46
42
  # example.
47
43
  # @return [String] the format flag.
@@ -72,7 +68,7 @@ class String
72
68
  end
73
69
 
74
70
  # Format the current string into the configured flag format in place as
75
- # described for {#flag}.
71
+ # described for {String#flag}.
76
72
  def flag!
77
73
  replace(flag)
78
74
  end
@@ -0,0 +1,212 @@
1
+ # frozen_string_literal: true
2
+
3
+ class String
4
+ # Encode an hexadecimal string to a decimal string
5
+ # @param opts [Hash] optional parameters
6
+ # @option opts [String] :prefix Prefix of the input. Default value is a void
7
+ # string. Example of values: +0x+, +\x+.
8
+ # @return [String] the decimal encoded string
9
+ # @example
10
+ # 'ff'.hex2dec # => "255"
11
+ # '\xf3'.hex2dec(prefix: '\x') # => "243"
12
+ def hex2dec(opts = {})
13
+ opts[:prefix] ||= ''
14
+ # remove prefix
15
+ out = sub(opts[:prefix], '')
16
+ # convert
17
+ return out.hex.to_s
18
+ end
19
+
20
+ # Encode an hexadecimal string to a decimal string in place as described
21
+ # for {String#hex2dec}.
22
+ # @example
23
+ # a = 'ff'
24
+ # a.hex2dec!
25
+ # a # => "255"
26
+ def hex2dec!(opts = {})
27
+ replace(hex2dec(opts))
28
+ end
29
+
30
+ # Encode an decimal string to a hexadecimal string
31
+ # @param opts [Hash] optional parameters
32
+ # @option opts [String] :prefix Prefix of the output. Default value is a void
33
+ # string. Example of values: +0x+, +\x+.
34
+ # @option opts [Symbol] :case Char case of the ouput. Default value +:lower+.
35
+ # Other valid value +:upper+.
36
+ # @return [String] the hexadecimal encoded string
37
+ # @example
38
+ # '255'.dec2hex # => "ff"
39
+ # '255'.dec2hex({prefix: '0x', case: :upper}) # => "0xFF"
40
+ def dec2hex(opts = {})
41
+ opts[:prefix] ||= ''
42
+ opts[:case] ||= :lower
43
+ # convert
44
+ out = to_i.to_s(16)
45
+ # char case management
46
+ out = out.upcase if opts[:case] == :upper
47
+ # adding prefix must be done after case change
48
+ return opts[:prefix] + out
49
+ end
50
+
51
+ # Encode an decimal string to a hexadecimal string in place as described
52
+ # for {String#dec2hex}.
53
+ # @example
54
+ # a = '255'
55
+ # a.dec2hex!
56
+ # a # => "ff"
57
+ def dec2hex!(opts = {})
58
+ replace(dec2hex(opts))
59
+ end
60
+
61
+ # Encode a string into hexadecimal
62
+ # @param opts [Hash] optional parameters
63
+ # @option opts [String] :prefix Prefix of the output. Default value is a void
64
+ # string. Example of values: +0x+, +\x+.
65
+ # @option opts [Symbol] :case Char case of the ouput. Default value +:lower+.
66
+ # Other valid value +:upper+.
67
+ # @option opts [Symbol] :nibble Display output with high nibble first
68
+ # (+:high+ default) or low nibble first (+:low+).
69
+ # @return [String] the hexadecimal encoded string
70
+ # @example
71
+ # 'noraj'.to_hex # => "6e6f72616a"
72
+ # 'noraj'.to_hex(prefix: '0x') # => "0x6e6f72616a"
73
+ # 'noraj'.to_hex(case: :upper) # => "6E6F72616A"
74
+ # 'noraj'.to_hex(nibble: :low) # => "e6f62716a6"
75
+ def to_hex(opts = {})
76
+ opts[:prefix] ||= ''
77
+ opts[:case] ||= :lower
78
+ opts[:nibble] ||= :high
79
+ # convert
80
+ out = ''
81
+ case opts[:nibble]
82
+ when :high
83
+ out = unpack1('H*')
84
+ when :low
85
+ out = unpack1('h*')
86
+ end
87
+ # char case management
88
+ out = out.upcase if opts[:case] == :upper
89
+ # adding prefix must be done after case change
90
+ return opts[:prefix] + out
91
+ end
92
+
93
+ # Alias for {String#to_hex}.
94
+ def str2hex(opts = {})
95
+ to_hex(opts)
96
+ end
97
+
98
+ # Encode a string into hexadecimal in place as described
99
+ # for {String#to_hex}.
100
+ # @example
101
+ # a = 'noraj'
102
+ # a.to_hex!
103
+ # a # => "6e6f72616a"
104
+ def to_hex!(opts = {})
105
+ replace(to_hex(opts))
106
+ end
107
+
108
+ # Alias for {String#to_hex!}.
109
+ def str2hex!(opts = {})
110
+ to_hex!(opts)
111
+ end
112
+
113
+ # Decode a hexadecimal string
114
+ # @param opts [Hash] optional parameters
115
+ # @option opts [String] :prefix Prefix of the input. Default value is a void
116
+ # string. Example of values: +0x+, +\x+.
117
+ # @option opts [Symbol] :nibble Display input with high nibble first
118
+ # (+:high+ default) or low nibble first (+:low+).
119
+ # @return [String] the hexadecimal decoded string
120
+ # @example
121
+ # "6e6f72616a".from_hex # => "noraj"
122
+ # "0x6e6f72616a".from_hex(prefix: '0x') # => "noraj"
123
+ # "e6f62716a6".from_hex(nibble: :low) # => "noraj"
124
+ def from_hex(opts = {})
125
+ opts[:prefix] ||= ''
126
+ opts[:nibble] ||= :high
127
+ # remove prefix
128
+ out = sub(opts[:prefix], '')
129
+ # convert
130
+ return Array(out).pack('H*') if opts[:nibble] == :high
131
+ return Array(out).pack('h*') if opts[:nibble] == :low
132
+
133
+ raise ArgumentError ':nibble expects :high or :low'
134
+ end
135
+
136
+ # Alias for {String#from_hex}.
137
+ def hex2str(opts = {})
138
+ from_hex(opts)
139
+ end
140
+
141
+ # Decode a hexadecimal string in place as described
142
+ # for {String#from_hex}.
143
+ # @example
144
+ # a = "6e6f72616a"
145
+ # a.from_hex!
146
+ # a # => "noraj"
147
+ def from_hex!(opts = {})
148
+ replace(from_hex(opts))
149
+ end
150
+
151
+ # Alias for {String#from_hex!}.
152
+ def hex2str!(opts = {})
153
+ from_hex!(opts)
154
+ end
155
+
156
+ # Encode an hexadecimal string to a binary string
157
+ # @param opts [Hash] optional parameters
158
+ # @option opts [String] :prefix Prefix of the input. Default value is a void
159
+ # string. Example of values: +0x+, +\x+.
160
+ # @return [String] the binary encoded string
161
+ # @example
162
+ # 'ab'.hex2bin # => "10101011"
163
+ # '\xf3'.hex2bin(prefix: '\x') # => "11110011"
164
+ def hex2bin(opts = {})
165
+ opts[:prefix] ||= ''
166
+ # remove prefix
167
+ out = sub(opts[:prefix], '')
168
+ # convert
169
+ return out.to_i(16).to_s(2)
170
+ end
171
+
172
+ # Encode an hexadecimal string to a binary string in place as described
173
+ # for {String#hex2bin}.
174
+ # @example
175
+ # a = 'ff'
176
+ # a.hex2bin!
177
+ # a # => => "11111111"
178
+ def hex2bin!(opts = {})
179
+ replace(hex2bin(opts))
180
+ end
181
+
182
+ # Encode an binary string to a hexadecimal string
183
+ # @param opts [Hash] optional parameters
184
+ # @option opts [String] :prefix Prefix of the output. Default value is a void
185
+ # string. Example of values: +0x+, +\x+.
186
+ # @option opts [Symbol] :case Char case of the ouput. Default value +:lower+.
187
+ # Other valid value +:upper+.
188
+ # @return [String] the hexadecimal encoded string
189
+ # @example
190
+ # '11110011'.bin2hex # => "f3"
191
+ # '11110011'.bin2hex({prefix: '0x', case: :upper}) # => "0xF3"
192
+ def bin2hex(opts = {})
193
+ opts[:prefix] ||= ''
194
+ opts[:case] ||= :lower
195
+ # convert
196
+ out = to_i(2).to_s(16)
197
+ # char case management
198
+ out = out.upcase if opts[:case] == :upper
199
+ # adding prefix must be done after case change
200
+ return opts[:prefix] + out
201
+ end
202
+
203
+ # Encode an binary string to a hexadecimal string in place as described
204
+ # for {String#bin2hex}.
205
+ # @example
206
+ # a = '11110011'
207
+ # a.bin2hex!
208
+ # a # => "f3"
209
+ def bin2hex!(opts = {})
210
+ replace(bin2hex(opts))
211
+ end
212
+ end
@@ -35,12 +35,12 @@ class String
35
35
  replace(rot(opts))
36
36
  end
37
37
 
38
- # Alias for {#rot} with default value ( +rot(shift: 13)+ ).
38
+ # Alias for {String#rot} with default value ( +rot(shift: 13)+ ).
39
39
  def rot13
40
40
  rot
41
41
  end
42
42
 
43
- # Alias for {#rot!} with default value ( +rot!(shift: 13)+ ).
43
+ # Alias for {String#rot!} with default value ( +rot!(shift: 13)+ ).
44
44
  def rot13!
45
45
  rot!
46
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Version
4
- VERSION = '1.0.0'
4
+ VERSION = '1.3.1'
5
5
  end