Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ctf_party/cgi.rb,
lib/ctf_party/dec.rb,
lib/ctf_party/hex.rb,
lib/ctf_party/rot.rb,
lib/ctf_party/case.rb,
lib/ctf_party/flag.rb,
lib/ctf_party/leet.rb,
lib/ctf_party/base64.rb,
lib/ctf_party/binary.rb,
lib/ctf_party/digest.rb
Constant Summary collapse
- @@flag =
The flag configuration hash. See flag=.
{ prefix: '', suffix: '', enclosing: ['{', '}'], digest: nil }
Class Method Summary collapse
-
.flag ⇒ Object
Show the actual flag configuration.
-
.flag=(hash) ⇒ Hash
Update the flag configuration.
Instance Method Summary collapse
-
#alternatecase(shift = 0) ⇒ String
Change one characte on two upcase and the other downcase.
-
#alternatecase!(shift = 0) ⇒ Object
Change one characte on two upcase and the other downcase in place as described for #alternatecase.
-
#b64?(opts = {}) ⇒ Boolean
Is the string encoded in base64?.
-
#bin2hex(opts = {}) ⇒ String
Encode an binary string to a hexadecimal string.
-
#bin2hex!(opts = {}) ⇒ Object
Encode an binary string to a hexadecimal string in place as described for #bin2hex.
-
#bin2str(opts = {}) ⇒ Object
Alias for #from_bin.
-
#bin2str!(opts = {}) ⇒ Object
Alias for #from_bin!.
-
#dec2hex(opts = {}) ⇒ String
Encode an decimal string to a hexadecimal string.
-
#dec2hex!(opts = {}) ⇒ Object
Encode an decimal string to a hexadecimal string in place as described for #dec2hex.
-
#dec2str ⇒ Object
Alias for #from_dec.
-
#dec2str! ⇒ Object
Alias for #from_dec!.
-
#flag ⇒ String
Format the current string into the configured flag format.
-
#flag! ⇒ Object
Format the current string into the configured flag format in place as described for #flag.
-
#flag? ⇒ Boolean
Check if the string respect the defined flag format.
-
#from_b64(opts = {}) ⇒ String
Decode the string from base64.
-
#from_b64!(opts = {}) ⇒ nil
Decode the string from base64 in place as described for #from_b64.
-
#from_bin(opts = {}) ⇒ String
Decode a binary string.
-
#from_bin!(opts = {}) ⇒ Object
Decode a binary string in place as described for #from_bin.
-
#from_dec ⇒ String
Decode a decimal string (decimal to hexadecimal then hexadecimal to string).
-
#from_dec! ⇒ Object
Decode a decimal string in place as described for #from_dec.
-
#from_hex(opts = {}) ⇒ String
Decode a hexadecimal string.
-
#from_hex!(opts = {}) ⇒ Object
Decode a hexadecimal string in place as described for #from_hex.
-
#from_hexip(opts = {}) ⇒ String
Decode a hexadecimal IP string into a dotted decimal one.
-
#from_hexip!(opts = {}) ⇒ Object
Decode a hexadecimal IP string into a dotted decimal one in place as described for #from_hexip.
-
#hex2bin(opts = {}) ⇒ String
Encode an hexadecimal string to a binary string.
-
#hex2bin!(opts = {}) ⇒ Object
Encode an hexadecimal string to a binary string in place as described for #hex2bin.
-
#hex2dec(opts = {}) ⇒ String
Encode an hexadecimal string to a decimal string.
-
#hex2dec!(opts = {}) ⇒ Object
Encode an hexadecimal string to a decimal string in place as described for #hex2dec.
-
#hex2str(opts = {}) ⇒ Object
Alias for #from_hex.
-
#hex2str!(opts = {}) ⇒ Object
Alias for #from_hex!.
-
#htmlescape ⇒ String
HTML escape the string.
-
#htmlescape! ⇒ Object
HTML escape the string in place as described for #htmlescape.
-
#htmlunescape ⇒ String
HTML unescape the string.
-
#htmlunescape! ⇒ Object
HTML unescape the string in place as described for #htmlunescape.
-
#leet ⇒ Object
Transform into leet speak (l337 5p34k).
-
#leet! ⇒ Object
Transform into leet speak (l337 5p34k) in place as described for #leet.
-
#md5 ⇒ String
Calculate the md5 hash of the string.
-
#md5! ⇒ Object
Calculate the md5 hash of the string in place as described for #md5.
-
#randomcase ⇒ String
Change the case of characters randomly.
-
#randomcase! ⇒ Object
Change the case of characters randomly in place as described for #randomcase.
-
#rmd160 ⇒ String
Calculate the RIPEMD-160 hash of the string.
-
#rmd160! ⇒ Object
Calculate the RIPEMD-160 hash of the string in place as described for #rmd160.
-
#rot(opts = {}) ⇒ String
“Encrypt / Decrypt” the string with Caesar cipher.
-
#rot!(opts = {}) ⇒ String
“Encrypt / Decrypt” the string with Caesar cipher in place as described for #rot.
-
#rot13 ⇒ Object
Alias for #rot with default value ( rot(shift: 13) ).
-
#rot13! ⇒ Object
Alias for #rot! with default value ( rot!(shift: 13) ).
-
#sha1 ⇒ String
Calculate the sha1 hash of the string.
-
#sha1! ⇒ Object
Calculate the sha1 hash of the string in place as described for #sha1.
-
#sha2(opts = {}) ⇒ String
Calculate the sha2 hash of the string.
-
#sha2!(opts = {}) ⇒ Object
Calculate the sha2 hash of the string in place as described for #sha2.
-
#sha2_256 ⇒ Object
Alias for #sha2 with default value ( sha2(bitlen: 256) ).
-
#sha2_256! ⇒ Object
Alias for #sha2! with default value ( sha2!(bitlen: 256) ).
-
#sha2_384 ⇒ Object
Alias for #sha2 with default value ( sha2(bitlen: 384) ).
-
#sha2_384! ⇒ Object
Alias for #sha2! with default value ( sha2!(bitlen: 384) ).
-
#sha2_512 ⇒ Object
Alias for #sha2 with default value ( sha2(bitlen: 512) ).
-
#sha2_512! ⇒ Object
Alias for #sha2! with default value ( sha2!(bitlen: 512) ).
-
#str2bin(opts = {}) ⇒ Object
Alias for #to_bin.
-
#str2bin!(opts = {}) ⇒ Object
Alias for #to_bin!.
-
#str2dec ⇒ Object
Alias for #to_dec.
-
#str2dec! ⇒ Object
Alias for #to_dec!.
-
#str2hex(opts = {}) ⇒ Object
Alias for #to_hex.
-
#str2hex!(opts = {}) ⇒ Object
Alias for #to_hex!.
-
#to_b64(opts = {}) ⇒ String
Encode the string into base64.
-
#to_b64!(opts = {}) ⇒ nil
Encode the string into base64 in place as described for #to_b64.
-
#to_bin(opts = {}) ⇒ String
Encode a string into binary.
-
#to_bin!(opts = {}) ⇒ Object
Encode a string into binary in place as described for #to_bin.
-
#to_dec ⇒ String
Encode a string into decimal (string to hexadecimal then hexadecimal to decimal).
-
#to_dec! ⇒ Object
Encode a string into decimal in place as described for #to_dec.
-
#to_hex(opts = {}) ⇒ String
Encode a string into hexadecimal.
-
#to_hex!(opts = {}) ⇒ Object
Encode a string into hexadecimal in place as described for #to_hex.
-
#to_hexip(opts = {}) ⇒ String
Encode a dotted decimal IP into a hexadecimal one.
-
#to_hexip!(opts = {}) ⇒ Object
Encode a dotted decimal IP into a hexadecimal one in place as described for #to_hexip.
-
#urldecode ⇒ String
URL-decode the string.
-
#urldecode! ⇒ Object
URL-decode the string in place as described for #urldecode.
-
#urlencode ⇒ String
URL-encode the string.
-
#urlencode! ⇒ Object
URL-encode the string in place as described for #urlencode.
Class Method Details
.flag ⇒ Object
Show the actual flag configuration. See flag=.
15 16 17 |
# File 'lib/ctf_party/flag.rb', line 15 def self.flag @@flag end |
.flag=(hash) ⇒ Hash
You can provide the full hash or only the key to update.
Update the flag configuration.
36 37 38 39 |
# File 'lib/ctf_party/flag.rb', line 36 def self.flag=(hash) hash.select! { |k, _v| @@flag.key?(k) } @@flag.merge!(hash) end |
Instance Method Details
#alternatecase(shift = 0) ⇒ String
Change one characte on two upcase and the other downcase
26 27 28 |
# File 'lib/ctf_party/case.rb', line 26 def alternatecase(shift = 0) chars.each_with_index.map { |c, i| (i + shift).even? ? c.downcase : c.upcase }.join end |
#alternatecase!(shift = 0) ⇒ Object
Change one characte on two upcase and the other downcase in place as described for #alternatecase.
32 33 34 |
# File 'lib/ctf_party/case.rb', line 32 def alternatecase!(shift = 0) replace(alternatecase(shift)) end |
#b64?(opts = {}) ⇒ Boolean
Is the string encoded in base64?
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ctf_party/base64.rb', line 69 def b64?(opts = {}) opts[:mode] ||= :strict b64 = false # https://www.rexegg.com/regex-ruby.html reg1 = %r{\A(?:[a-zA-Z0-9+/]{4})*(?:|(?:[a-zA-Z0-9+/]{3}=)| (?:[a-zA-Z0-9+/]{2}==)|(?:[a-zA-Z0-9+/]{1}===))\Z}xn reg3 = /\A(?:[a-zA-Z0-9\-_]{4})*(?:|(?:[a-zA-Z0-9\-_]{3}=)| (?:[a-zA-Z0-9\-_]{2}==)|(?:[a-zA-Z0-9\-_]{1}===))\Z/xn case opts[:mode] when :strict, :rfc4648 b64 = true if reg1.match?(self) when :rfc2045 b64 = true split("\n").each do |s| b64 = false unless reg1.match?(s) end when :urlsafe b64 = true if reg3.match?(self) else raise ArgumentError 'Wrong mode' end return b64 end |
#bin2hex(opts = {}) ⇒ String
Encode an binary string to a hexadecimal string
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/ctf_party/hex.rb', line 197 def bin2hex(opts = {}) opts[:prefix] ||= '' opts[:case] ||= :lower # convert out = to_i(2).to_s(16) # char case management out = out.upcase if opts[:case] == :upper # adding prefix must be done after case change return opts[:prefix] + out end |
#bin2hex!(opts = {}) ⇒ Object
Encode an binary string to a hexadecimal string in place as described for #bin2hex.
214 215 216 |
# File 'lib/ctf_party/hex.rb', line 214 def bin2hex!(opts = {}) replace(bin2hex(opts)) end |
#bin2str(opts = {}) ⇒ Object
Alias for #from_bin.
59 60 61 |
# File 'lib/ctf_party/binary.rb', line 59 def bin2str(opts = {}) from_bin(opts) end |
#bin2str!(opts = {}) ⇒ Object
Alias for #from_bin!.
74 75 76 |
# File 'lib/ctf_party/binary.rb', line 74 def bin2str!(opts = {}) from_bin!(opts) end |
#dec2hex(opts = {}) ⇒ String
Encode an decimal string to a hexadecimal string
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ctf_party/hex.rb', line 42 def dec2hex(opts = {}) opts[:prefix] ||= '' opts[:case] ||= :lower opts[:padding] ||= 1 # convert out = to_i.to_s(16) # padding out = ('0' * (opts[:padding] - 1)) + out if out.size < opts[:padding] # char case management out = out.upcase if opts[:case] == :upper # adding prefix must be done after case change return opts[:prefix] + out end |
#dec2hex!(opts = {}) ⇒ Object
Encode an decimal string to a hexadecimal string in place as described for #dec2hex.
62 63 64 |
# File 'lib/ctf_party/hex.rb', line 62 def dec2hex!(opts = {}) replace(dec2hex(opts)) end |
#dec2str ⇒ Object
Alias for #from_dec.
41 42 43 |
# File 'lib/ctf_party/dec.rb', line 41 def dec2str from_dec end |
#dec2str! ⇒ Object
Alias for #from_dec!.
46 47 48 |
# File 'lib/ctf_party/dec.rb', line 46 def dec2str! replace(dec2str) end |
#flag ⇒ String
Format the current string into the configured flag format. See flag= example.
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 |
# File 'lib/ctf_party/flag.rb', line 44 def flag flag = '' flag += @@flag[:prefix] flag += @@flag[:enclosing][0] if @@flag[:digest].nil? flag += self else case @@flag[:digest] when 'md5' flag += md5 when 'sha1' flag += sha1 when 'sha2_256' flag += sha2_256 when 'sha2_384' flag += sha2_384 when 'sha2_512' flag += sha2_512 when 'rmd160' flag += rmd160 end end flag += @@flag[:enclosing][1] flag + @@flag[:suffix] end |
#flag! ⇒ Object
Format the current string into the configured flag format in place as described for #flag.
72 73 74 |
# File 'lib/ctf_party/flag.rb', line 72 def flag! replace(flag) end |
#flag? ⇒ Boolean
Check if the string respect the defined flag format.
86 87 88 89 |
# File 'lib/ctf_party/flag.rb', line 86 def flag? /#{@@flag[:prefix]}#{@@flag[:enclosing][0]}[[:print:]]+ #{@@flag[:enclosing][1]}#{@@flag[:suffix]}/ox.match?(self) end |
#from_b64(opts = {}) ⇒ String
Decode the string from base64
41 42 43 44 45 46 47 |
# File 'lib/ctf_party/base64.rb', line 41 def from_b64(opts = {}) opts[:mode] ||= :strict return Base64.strict_decode64(self) if opts[:mode] == :strict || opts[:mode] == :rfc4648 return Base64.decode64(self) if opts[:mode] == :rfc2045 return Base64.urlsafe_decode64(self) if opts[:mode] == :urlsafe end |
#from_b64!(opts = {}) ⇒ nil
Decode the string from base64 in place as described for #from_b64.
55 56 57 |
# File 'lib/ctf_party/base64.rb', line 55 def from_b64!(opts = {}) replace(from_b64(opts)) end |
#from_bin(opts = {}) ⇒ String
Decode a binary string
49 50 51 52 53 54 55 56 |
# File 'lib/ctf_party/binary.rb', line 49 def from_bin(opts = {}) opts[:bitnumbering] ||= :MSB # convert return Array(self).pack('B*') if opts[:bitnumbering] == :MSB return Array(self).pack('b*') if opts[:bitnumbering] == :LSB raise ArgumentError ':bitnumbering expects :MSB or :LSB' end |
#from_bin!(opts = {}) ⇒ Object
Decode a binary string in place as described for #from_bin.
69 70 71 |
# File 'lib/ctf_party/binary.rb', line 69 def from_bin!(opts = {}) replace(from_bin(opts)) end |
#from_dec ⇒ String
Decode a decimal string (decimal to hexadecimal then hexadecimal to string)
21 22 23 |
# File 'lib/ctf_party/dec.rb', line 21 def from_dec dec2hex.hex2str end |
#from_dec! ⇒ Object
Decode a decimal string in place as described for #from_dec.
26 27 28 |
# File 'lib/ctf_party/dec.rb', line 26 def from_dec! replace(from_dec) end |
#from_hex(opts = {}) ⇒ String
Decode a hexadecimal string
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ctf_party/hex.rb', line 129 def from_hex(opts = {}) opts[:prefix] ||= '' opts[:nibble] ||= :high # remove prefix out = sub(opts[:prefix], '') # convert return Array(out).pack('H*') if opts[:nibble] == :high return Array(out).pack('h*') if opts[:nibble] == :low raise ArgumentError ':nibble expects :high or :low' end |
#from_hex!(opts = {}) ⇒ Object
Decode a hexadecimal string in place as described for #from_hex.
152 153 154 |
# File 'lib/ctf_party/hex.rb', line 152 def from_hex!(opts = {}) replace(from_hex(opts)) end |
#from_hexip(opts = {}) ⇒ String
Decode a hexadecimal IP string into a dotted decimal one
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/ctf_party/hex.rb', line 228 def from_hexip(opts = {}) opts[:prefix] ||= '' opts[:nibble] ||= :high # remove prefix out = sub(opts[:prefix], '') # convert out = out.scan(/.{2}/).map(&:hex2dec) out = out.reverse if opts[:nibble] == :low out.join('.') end |
#from_hexip!(opts = {}) ⇒ Object
Decode a hexadecimal IP string into a dotted decimal one in place as described for #from_hexip.
241 242 243 |
# File 'lib/ctf_party/hex.rb', line 241 def from_hexip!(opts = {}) replace(from_hexip(opts)) end |
#hex2bin(opts = {}) ⇒ String
Encode an hexadecimal string to a binary string
169 170 171 172 173 174 175 |
# File 'lib/ctf_party/hex.rb', line 169 def hex2bin(opts = {}) opts[:prefix] ||= '' # remove prefix out = sub(opts[:prefix], '') # convert return out.to_i(16).to_s(2) end |
#hex2bin!(opts = {}) ⇒ Object
Encode an hexadecimal string to a binary string in place as described for #hex2bin.
183 184 185 |
# File 'lib/ctf_party/hex.rb', line 183 def hex2bin!(opts = {}) replace(hex2bin(opts)) end |
#hex2dec(opts = {}) ⇒ String
Encode an hexadecimal string to a decimal string
12 13 14 15 16 17 18 |
# File 'lib/ctf_party/hex.rb', line 12 def hex2dec(opts = {}) opts[:prefix] ||= '' # remove prefix out = sub(opts[:prefix], '') # convert return out.hex.to_s end |
#hex2dec!(opts = {}) ⇒ Object
Encode an hexadecimal string to a decimal string in place as described for #hex2dec.
26 27 28 |
# File 'lib/ctf_party/hex.rb', line 26 def hex2dec!(opts = {}) replace(hex2dec(opts)) end |
#hex2str(opts = {}) ⇒ Object
Alias for #from_hex.
142 143 144 |
# File 'lib/ctf_party/hex.rb', line 142 def hex2str(opts = {}) from_hex(opts) end |
#hex2str!(opts = {}) ⇒ Object
Alias for #from_hex!.
157 158 159 |
# File 'lib/ctf_party/hex.rb', line 157 def hex2str!(opts = {}) from_hex!(opts) end |
#htmlescape ⇒ String
HTML escape the string
37 38 39 |
# File 'lib/ctf_party/cgi.rb', line 37 def htmlescape CGI.escapeHTML self end |
#htmlescape! ⇒ Object
HTML escape the string in place as described for #htmlescape.
42 43 44 |
# File 'lib/ctf_party/cgi.rb', line 42 def htmlescape! replace(htmlescape) end |
#htmlunescape ⇒ String
HTML unescape the string
50 51 52 |
# File 'lib/ctf_party/cgi.rb', line 50 def htmlunescape CGI.unescapeHTML self end |
#htmlunescape! ⇒ Object
HTML unescape the string in place as described for #htmlunescape.
55 56 57 |
# File 'lib/ctf_party/cgi.rb', line 55 def htmlunescape! replace(htmlunescape) end |
#leet ⇒ Object
Transform into leet speak (l337 5p34k)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ctf_party/leet.rb', line 8 def leet tr = { 'T' => '7', 'E' => '3', 'I' => '1', 'L' => '1', 'O' => '0', 'S' => '5', 'A' => '4', 'G' => '6', 'B' => '8' } tr.merge! tr.transform_keys(&:downcase) gsub(/[#{tr.keys.join}]/i, **tr) end |
#leet! ⇒ Object
Transform into leet speak (l337 5p34k) in place as described for #leet.
26 27 28 |
# File 'lib/ctf_party/leet.rb', line 26 def leet! replace(leet) end |
#md5 ⇒ String
Calculate the md5 hash of the string.
12 13 14 |
# File 'lib/ctf_party/digest.rb', line 12 def md5 Digest::MD5.hexdigest self end |
#md5! ⇒ Object
Calculate the md5 hash of the string in place as described for #md5.
21 22 23 |
# File 'lib/ctf_party/digest.rb', line 21 def md5! replace(md5) end |
#randomcase ⇒ String
Change the case of characters randomly
9 10 11 |
# File 'lib/ctf_party/case.rb', line 9 def randomcase chars.map { |c| rand(0..1).zero? ? c.downcase : c.upcase }.join end |
#randomcase! ⇒ Object
Change the case of characters randomly in place as described for #randomcase.
15 16 17 |
# File 'lib/ctf_party/case.rb', line 15 def randomcase! replace(randomcase) end |
#rmd160 ⇒ String
Calculate the RIPEMD-160 hash of the string.
104 105 106 |
# File 'lib/ctf_party/digest.rb', line 104 def rmd160 Digest::RMD160.hexdigest self end |
#rmd160! ⇒ Object
Calculate the RIPEMD-160 hash of the string in place as described for #rmd160.
114 115 116 |
# File 'lib/ctf_party/digest.rb', line 114 def rmd160! replace(rmd160) end |
#rot(opts = {}) ⇒ String
“Encrypt / Decrypt” the string with Caesar cipher. This will shift the alphabet letters by n, where n is the integer key. The same function is used for encryption / decryption.
16 17 18 19 20 21 22 23 24 |
# File 'lib/ctf_party/rot.rb', line 16 def rot(opts = {}) opts[:shift] ||= 13 alphabet = Array('a'..'z') lowercase = Hash[alphabet.zip(alphabet.rotate(opts[:shift]))] alphabet = Array('A'..'Z') uppercasecase = Hash[alphabet.zip(alphabet.rotate(opts[:shift]))] encrypter = lowercase.merge(uppercasecase) chars.map { |c| encrypter.fetch(c, c) }.join end |
#rot!(opts = {}) ⇒ String
“Encrypt / Decrypt” the string with Caesar cipher in place as described for #rot.
34 35 36 |
# File 'lib/ctf_party/rot.rb', line 34 def rot!(opts = {}) replace(rot(opts)) end |
#rot13 ⇒ Object
Alias for #rot with default value ( rot(shift: 13) ).
39 40 41 |
# File 'lib/ctf_party/rot.rb', line 39 def rot13 rot end |
#rot13! ⇒ Object
Alias for #rot! with default value ( rot!(shift: 13) ).
44 45 46 |
# File 'lib/ctf_party/rot.rb', line 44 def rot13! rot! end |
#sha1 ⇒ String
Calculate the sha1 hash of the string.
30 31 32 |
# File 'lib/ctf_party/digest.rb', line 30 def sha1 Digest::SHA1.hexdigest self end |
#sha1! ⇒ Object
Calculate the sha1 hash of the string in place as described for
{String#sha1}.
40 41 42 |
# File 'lib/ctf_party/digest.rb', line 40 def sha1! replace(sha1) end |
#sha2(opts = {}) ⇒ String
Calculate the sha2 hash of the string.
54 55 56 57 |
# File 'lib/ctf_party/digest.rb', line 54 def sha2(opts = {}) opts[:bitlen] ||= 256 Digest::SHA2.new(opts[:bitlen]).hexdigest self end |
#sha2!(opts = {}) ⇒ Object
Calculate the sha2 hash of the string in place as described for
{String#sha2}.
65 66 67 |
# File 'lib/ctf_party/digest.rb', line 65 def sha2!(opts = {}) replace(sha2(opts)) end |
#sha2_256 ⇒ Object
Alias for #sha2 with default value ( sha2(bitlen: 256) ).
70 71 72 |
# File 'lib/ctf_party/digest.rb', line 70 def sha2_256 sha2 end |
#sha2_256! ⇒ Object
Alias for #sha2! with default value ( sha2!(bitlen: 256) ).
75 76 77 |
# File 'lib/ctf_party/digest.rb', line 75 def sha2_256! replace(sha2) end |
#sha2_384 ⇒ Object
Alias for #sha2 with default value ( sha2(bitlen: 384) ).
80 81 82 |
# File 'lib/ctf_party/digest.rb', line 80 def sha2_384 sha2(bitlen: 384) end |
#sha2_384! ⇒ Object
Alias for #sha2! with default value ( sha2!(bitlen: 384) ).
85 86 87 |
# File 'lib/ctf_party/digest.rb', line 85 def sha2_384! replace(sha2(bitlen: 384)) end |
#sha2_512 ⇒ Object
Alias for #sha2 with default value ( sha2(bitlen: 512) ).
90 91 92 |
# File 'lib/ctf_party/digest.rb', line 90 def sha2_512 sha2(bitlen: 512) end |
#sha2_512! ⇒ Object
Alias for #sha2! with default value ( sha2!(bitlen: 512) ).
95 96 97 |
# File 'lib/ctf_party/digest.rb', line 95 def sha2_512! replace(sha2(bitlen: 512)) end |
#str2bin(opts = {}) ⇒ Object
Alias for #to_bin.
22 23 24 |
# File 'lib/ctf_party/binary.rb', line 22 def str2bin(opts = {}) to_bin(opts) end |
#str2bin!(opts = {}) ⇒ Object
Alias for #to_bin!.
37 38 39 |
# File 'lib/ctf_party/binary.rb', line 37 def str2bin!(opts = {}) to_bin!(opts) end |
#str2dec ⇒ Object
Alias for #to_dec.
31 32 33 |
# File 'lib/ctf_party/dec.rb', line 31 def str2dec to_dec end |
#str2dec! ⇒ Object
Alias for #to_dec!.
36 37 38 |
# File 'lib/ctf_party/dec.rb', line 36 def str2dec! replace(str2dec) end |
#str2hex(opts = {}) ⇒ Object
Alias for #to_hex.
99 100 101 |
# File 'lib/ctf_party/hex.rb', line 99 def str2hex(opts = {}) to_hex(opts) end |
#str2hex!(opts = {}) ⇒ Object
Alias for #to_hex!.
114 115 116 |
# File 'lib/ctf_party/hex.rb', line 114 def str2hex!(opts = {}) to_hex!(opts) end |
#to_b64(opts = {}) ⇒ String
Encode the string into base64
15 16 17 18 19 20 21 |
# File 'lib/ctf_party/base64.rb', line 15 def to_b64(opts = {}) opts[:mode] ||= :strict return Base64.strict_encode64(self) if opts[:mode] == :strict || opts[:mode] == :rfc4648 return Base64.encode64(self) if opts[:mode] == :rfc2045 return Base64.urlsafe_encode64(self) if opts[:mode] == :urlsafe end |
#to_b64!(opts = {}) ⇒ nil
Encode the string into base64 in place as described for #to_b64.
29 30 31 |
# File 'lib/ctf_party/base64.rb', line 29 def to_b64!(opts = {}) replace(to_b64(opts)) end |
#to_bin(opts = {}) ⇒ String
Encode a string into binary
12 13 14 15 16 17 18 19 |
# File 'lib/ctf_party/binary.rb', line 12 def to_bin(opts = {}) opts[:bitnumbering] ||= :MSB # convert return unpack1('B*') if opts[:bitnumbering] == :MSB return unpack1('b*') if opts[:bitnumbering] == :LSB raise ArgumentError ':bitnumbering expects :MSB or :LSB' end |
#to_bin!(opts = {}) ⇒ Object
Encode a string into binary in place as described for #to_bin.
32 33 34 |
# File 'lib/ctf_party/binary.rb', line 32 def to_bin!(opts = {}) replace(to_bin(opts)) end |
#to_dec ⇒ String
Encode a string into decimal (string to hexadecimal then hexadecimal to decimal)
8 9 10 |
# File 'lib/ctf_party/dec.rb', line 8 def to_dec str2hex.hex2dec end |
#to_dec! ⇒ Object
Encode a string into decimal in place as described for #to_dec.
13 14 15 |
# File 'lib/ctf_party/dec.rb', line 13 def to_dec! replace(to_dec) end |
#to_hex(opts = {}) ⇒ String
Encode a string into hexadecimal
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ctf_party/hex.rb', line 80 def to_hex(opts = {}) opts[:prefix] ||= '' opts[:case] ||= :lower opts[:nibble] ||= :high # convert out = '' case opts[:nibble] when :high out = unpack1('H*') when :low out = unpack1('h*') end # char case management out = out.upcase if opts[:case] == :upper # adding prefix must be done after case change return opts[:prefix] + out end |
#to_hex!(opts = {}) ⇒ Object
Encode a string into hexadecimal in place as described for #to_hex.
109 110 111 |
# File 'lib/ctf_party/hex.rb', line 109 def to_hex!(opts = {}) replace(to_hex(opts)) end |
#to_hexip(opts = {}) ⇒ String
Encode a dotted decimal IP into a hexadecimal one
257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/ctf_party/hex.rb', line 257 def to_hexip(opts = {}) opts[:prefix] ||= '' opts[:case] ||= :lower opts[:nibble] ||= :high # convert out = split('.').map { |x| x.dec2hex(padding: 2) } out = out.reverse if opts[:nibble] == :low out = out.join # char case management out = out.upcase if opts[:case] == :upper # adding prefix must be done after case change return opts[:prefix] + out end |
#to_hexip!(opts = {}) ⇒ Object
Encode a dotted decimal IP into a hexadecimal one in place as described for #to_hexip.
273 274 275 |
# File 'lib/ctf_party/hex.rb', line 273 def to_hexip!(opts = {}) replace(to_hexip(opts)) end |
#urldecode ⇒ String
URL-decode the string
24 25 26 |
# File 'lib/ctf_party/cgi.rb', line 24 def urldecode CGI.unescape self end |
#urldecode! ⇒ Object
URL-decode the string in place as described for #urldecode.
29 30 31 |
# File 'lib/ctf_party/cgi.rb', line 29 def urldecode! replace(urldecode) end |
#urlencode ⇒ String
URL-encode the string
11 12 13 |
# File 'lib/ctf_party/cgi.rb', line 11 def urlencode CGI.escape self end |
#urlencode! ⇒ Object
URL-encode the string in place as described for #urlencode.
16 17 18 |
# File 'lib/ctf_party/cgi.rb', line 16 def urlencode! replace(urlencode) end |