Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/ronin/support/core_ext/string.rb,
lib/ronin/support/text/core_ext/string.rb,
lib/ronin/support/binary/core_ext/string.rb,
lib/ronin/support/crypto/core_ext/string.rb,
lib/ronin/support/encoding/core_ext/string.rb,
lib/ronin/support/text/typo/core_ext/string.rb,
lib/ronin/support/encoding/c/core_ext/string.rb,
lib/ronin/support/compression/core_ext/string.rb,
lib/ronin/support/encoding/js/core_ext/string.rb,
lib/ronin/support/encoding/hex/core_ext/string.rb,
lib/ronin/support/encoding/sql/core_ext/string.rb,
lib/ronin/support/encoding/uri/core_ext/string.rb,
lib/ronin/support/encoding/xml/core_ext/string.rb,
lib/ronin/support/text/entropy/core_ext/string.rb,
lib/ronin/support/encoding/html/core_ext/string.rb,
lib/ronin/support/encoding/http/core_ext/string.rb,
lib/ronin/support/encoding/ruby/core_ext/string.rb,
lib/ronin/support/encoding/shell/core_ext/string.rb,
lib/ronin/support/text/homoglyph/core_ext/string.rb,
lib/ronin/support/binary/bit_flip/core_ext/string.rb,
lib/ronin/support/encoding/base16/core_ext/string.rb,
lib/ronin/support/encoding/base32/core_ext/string.rb,
lib/ronin/support/encoding/base36/core_ext/string.rb,
lib/ronin/support/encoding/base62/core_ext/string.rb,
lib/ronin/support/encoding/base64/core_ext/string.rb,
lib/ronin/support/binary/unhexdump/core_ext/string.rb,
lib/ronin/support/encoding/punycode/core_ext/string.rb,
lib/ronin/support/encoding/powershell/core_ext/string.rb,
lib/ronin/support/encoding/uuencoding/core_ext/string.rb,
lib/ronin/support/encoding/quoted_printable/core_ext/string.rb
Overview
Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
ronin-support is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
ronin-support is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with ronin-support. If not, see https://www.gnu.org/licenses/.
Class Method Summary collapse
-
.ascii(string) ⇒ String
Creates a new ASCII encoding string.
Instance Method Summary collapse
-
#aes128_decrypt(**kwargs) ⇒ String
Decrypts the String using AES-128.
-
#aes128_encrypt(**kwargs) ⇒ String
Encrypts the String using AES-128.
-
#aes256_decrypt(**kwargs) ⇒ String
Decrypts the String using AES-256.
-
#aes256_encrypt(**kwargs) ⇒ String
Encrypts the String using AES-256.
-
#aes_decrypt(**kwargs) ⇒ String
Decrypts the String using AES.
-
#aes_encrypt(**kwargs) ⇒ String
Encrypts the String using AES.
-
#base16_decode ⇒ String
[Base16] decodes the String.
-
#base16_encode ⇒ String
[Base16] encodes the String.
-
#base32_decode ⇒ String
[Base32] decodes the String.
-
#base32_encode ⇒ String
[Base32] encodes the String.
-
#base36_decode ⇒ Integer
[Base36] decodes the String.
-
#base62_decode ⇒ Integer
[Base62] decodes the String.
-
#base64_decode(mode: nil) ⇒ String
[Base64] decodes a string.
-
#base64_encode(mode: nil) ⇒ String
[Base64] encodes a string.
-
#bit_flips ⇒ Array<String>
(also: #flip_bits)
Returns every bit flip of every byte in the string.
-
#c_encode ⇒ String
C escapes every character in the String.
-
#c_escape ⇒ String
Escapes a String for C.
-
#c_string ⇒ String
Converts the String into a C string.
-
#c_unescape ⇒ String
(also: #c_decode)
Unescapes a C escaped String.
-
#c_unquote ⇒ String
Removes the quotes an unescapes a C string.
-
#common_prefix(other) ⇒ String
The common prefix of the string and the specified other string.
-
#common_suffix(other) ⇒ String
Finds the common suffix of the string and the specified other string.
-
#decrypt(cipher, **kwargs) ⇒ String
Decrypts the String.
-
#each_bit_flip {|string| ... } ⇒ Enumerator
Enumerates over every bit flip of every byte in the string.
-
#each_homoglyph(**kwargs) {|homoglyph| ... } ⇒ Enumerator
Enumerates over every homoglyph variation of the String.
-
#each_substring(min = 1) {|substring, (index)| ... } ⇒ String
Enumerates over every sub-string within the string.
-
#each_typo(**kwargs) {|typoed| ... } ⇒ Enumerator
Enumerates over every typo mistake for the String.
-
#each_unique_substring(min = 1) {|substring, (index)| ... } ⇒ String
Enumerates over the unique sub-strings contained in the string.
-
#encode_bytes(include: nil, exclude: nil) {|byte| ... } ⇒ String
Creates a new String by formatting each byte.
-
#encode_chars(include: nil, exclude: nil) {|char| ... } ⇒ String
Creates a new String by formatting each character.
-
#encrypt(cipher, **kwargs) ⇒ String
Encrypts the String.
-
#entropy(**kwargs) ⇒ Float
Calculates the entropy for the given string.
-
#gunzip ⇒ String
Gzip uncompresses the string.
-
#gzip ⇒ String
Gzip compresses the string.
-
#hex_decode ⇒ String
Hex-decodes the String.
-
#hex_encode ⇒ String
Hex-encodes characters in the String.
-
#hex_escape ⇒ String
Hex-escapes the characters within the String.
-
#hex_string ⇒ String
Converts the String into a double-quoted hex string.
-
#hex_unescape ⇒ String
Unescapes the characters within the String.
-
#hex_unquote ⇒ String
Removes the quotes and unescapes a hex string.
-
#hmac(key:, digest: :sha1) ⇒ String
Calculates the HMAC of the String.
-
#homoglyph(**kwargs) ⇒ String
Returns a random homoglyph substitution of the String.
-
#homoglyphs(**kwargs) {|homoglyph| ... } ⇒ Array<String>
Returns every homoglyph variation of the String.
-
#html_encode(**kwargs) ⇒ String
Encodes the chars in the String for HTML.
-
#html_escape(**kwargs) ⇒ String
HTML escapes the String.
-
#html_unescape ⇒ String
(also: #html_decode)
Unescapes the HTML encoded String.
-
#http_decode ⇒ String
HTTP decodes the HTTP encoded String.
-
#http_encode(**kwargs) ⇒ String
HTTP encodes each byte of the String.
-
#http_escape(**kwargs) ⇒ String
HTTP escapes the String.
-
#http_unescape ⇒ String
HTTP unescapes the String.
-
#insert_after(pattern, data) ⇒ String
Inserts data after the occurrence of a pattern.
-
#insert_before(pattern, data) ⇒ String
Inserts data before the occurrence of a pattern.
-
#js_encode ⇒ String
JavaScript escapes every character of the String.
-
#js_escape ⇒ String
Escapes a String for JavaScript.
-
#js_string ⇒ String
Converts the String into a JavaScript string.
-
#js_unescape ⇒ String
(also: #js_decode)
Unescapes a JavaScript escaped String.
-
#js_unquote ⇒ String
Removes the quotes an unescapes a JavaScript string.
-
#md5 ⇒ String
The MD5 checksum of the String.
-
#pad(padding, length) ⇒ String
Creates a new String by padding the String with repeating text, out to a specified length.
-
#powershell_encode ⇒ String
(also: #psh_encode)
[PowerShell encodes][1] every character in the String.
-
#powershell_escape ⇒ String
(also: #psh_escape)
[PowerShell escapes][1] the characters in the String.
-
#powershell_string ⇒ String
(also: #psh_string)
Converts the String into a double-quoted PowerShell escaped String.
-
#powershell_unescape ⇒ String
(also: #psh_unescape, #powershell_decode)
[PowerShell unescapes][1] the characters in the String.
-
#powershell_unquote ⇒ String
(also: #psh_unquote)
Removes the quotes an unescapes a PowerShell string.
-
#punycode_decode ⇒ String
Decodes a [punycode] String back into unicode.
-
#punycode_encode ⇒ String
Encodes a unicode String into [punycode].
-
#quoted_printable_escape ⇒ String
(also: #quoted_printable_encode, #qp_escape, #qp_encode)
Escapes the String as [Quoted-Printable].
-
#quoted_printable_unescape ⇒ String
(also: #quoted_printable_decode, #qp_decode, #qp_unescape)
Unescapes a [Quoted-Printable] encoded String.
-
#random_case ⇒ String
Creates a new String by randomizing the case of each character in the String.
-
#rmd160 ⇒ String
Calculates the RMD160 checksum for the String.
-
#rot(n = 13, **kwargs) ⇒ String
Rotates the characters in the string using the given alphabet.
-
#rsa_decrypt(**kwargs) ⇒ String
Decrypts the String using the given RSA key.
-
#rsa_encrypt(**kwargs) ⇒ String
Encrypts the String using the given RSA key.
-
#ruby_encode ⇒ String
Ruby escapes every character in the String.
-
#ruby_escape ⇒ String
(also: #escape)
Escapes a String for Ruby.
-
#ruby_string ⇒ String
Rubyonverts the String into a Ruby string.
-
#ruby_unescape ⇒ String
(also: #unescape, #ruby_decode)
Unescapes a Ruby escaped String.
-
#ruby_unquote ⇒ String
Removes the quotes an unescapes a Ruby string.
-
#sha1 ⇒ String
(also: #sha128)
The SHA1 checksum of the String.
-
#sha256 ⇒ String
(also: #sha2)
The SHA256 checksum of the String.
-
#sha512 ⇒ String
The SHA512 checksum of the String.
-
#shell_encode ⇒ String
Shell encodes every character in the String.
-
#shell_escape ⇒ String
Shell escapes the characters in the String.
-
#shell_string ⇒ String
Converts the String into a double-quoted shell escaped String.
-
#shell_unescape ⇒ String
(also: #shell_decode)
Shell unescapes the characters in the String.
-
#shell_unquote ⇒ String
Removes the quotes an unescapes a shell string.
-
#sql_decode ⇒ Object
Returns the SQL decoded form of the String.
-
#sql_encode ⇒ Object
Returns the SQL hex-string encoded form of the String.
-
#sql_escape(**kwargs) ⇒ String
Escapes an String for SQL.
-
#sql_unescape ⇒ String
Unescapes a SQL String.
-
#to_ascii ⇒ String
Converts the string into an ASCII encoded string.
-
#to_utf8 ⇒ String
Converts the string into an UTF-8 encoded string.
-
#typo(**kwargs) ⇒ String
Returns a random typo substitution for the String.
-
#typos(**kwargs) ⇒ Array<String>
Returns every typo for the String.
-
#uncommon_substring(other) ⇒ String
Finds the uncommon sub-string within the specified other string, which does not occur within the string.
-
#unhexdump(**kwargs) ⇒ String
Converts a multitude of hexdump formats back into raw-data.
-
#unpack(*arguments, **kwargs) ⇒ Array
Unpacks the String.
-
#unpack1(argument, **kwargs) ⇒ Integer, ...
Unpacks a single value from the String.
- #unpack1_original ⇒ Object
- #unpack_original ⇒ Object
-
#uri_encode(**kwargs) ⇒ String
URI encodes the String.
-
#uri_escape(**kwargs) ⇒ String
URI escapes the String.
-
#uri_form_encode(**kwargs) ⇒ String
(also: #www_form_encode)
URI Form encodes every character in the String.
-
#uri_form_escape(**kwargs) ⇒ String
(also: #www_form_escape)
URI Form escapes the String.
-
#uri_form_unescape ⇒ String
(also: #www_form_unescape, #uri_form_decode)
URI Form unescapes the String.
-
#uri_unescape ⇒ String
(also: #uri_decode)
URI unescapes the String.
-
#uu_decode ⇒ String
(also: #uudecode, #uu_unescape)
Decodes the [uuencoded][uuencoding] String.
-
#uu_encode ⇒ String
(also: #uuencode, #uu_escape)
[uuencodes][uuencoding] the String.
-
#xml_encode(**kwargs) ⇒ String
Encodes each character in the String as an XML character.
-
#xml_escape(**kwargs) ⇒ String
XML escapes the String.
-
#xml_unescape ⇒ String
(also: #xml_decode)
Unescapes the XML encoded String.
-
#xor(key) ⇒ String
(also: #^)
XOR encodes the String.
-
#zlib_deflate ⇒ String
Zlib deflate a string.
-
#zlib_inflate ⇒ String
Zlib inflate a string.
Class Method Details
.ascii(string) ⇒ String
Creates a new ASCII encoding string.
34 35 36 |
# File 'lib/ronin/support/core_ext/string.rb', line 34 def self.ascii(string) string.encode(Encoding::ASCII_8BIT) end |
Instance Method Details
#aes128_decrypt(**kwargs) ⇒ String
Decrypts the String using AES-128.
376 377 378 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 376 def aes128_decrypt(**kwargs) Ronin::Support::Crypto.aes128_decrypt(self,**kwargs) end |
#aes128_encrypt(**kwargs) ⇒ String
Encrypts the String using AES-128.
336 337 338 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 336 def aes128_encrypt(**kwargs) Ronin::Support::Crypto.aes128_encrypt(self,**kwargs) end |
#aes256_decrypt(**kwargs) ⇒ String
Decrypts the String using AES-256.
456 457 458 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 456 def aes256_decrypt(**kwargs) Ronin::Support::Crypto.aes256_decrypt(self,**kwargs) end |
#aes256_encrypt(**kwargs) ⇒ String
Encrypts the String using AES-256.
416 417 418 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 416 def aes256_encrypt(**kwargs) Ronin::Support::Crypto.aes256_encrypt(self,**kwargs) end |
#aes_decrypt(**kwargs) ⇒ String
Decrypts the String using AES.
296 297 298 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 296 def aes_decrypt(**kwargs) Ronin::Support::Crypto.aes_decrypt(self,**kwargs) end |
#aes_encrypt(**kwargs) ⇒ String
Encrypts the String using AES.
253 254 255 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 253 def aes_encrypt(**kwargs) Ronin::Support::Crypto.aes_encrypt(self,**kwargs) end |
#base16_decode ⇒ String
Base16 decodes the String.
59 60 61 |
# File 'lib/ronin/support/encoding/base16/core_ext/string.rb', line 59 def base16_decode Ronin::Support::Encoding::Base16.decode(self) end |
#base16_encode ⇒ String
Base16 encodes the String.
39 40 41 |
# File 'lib/ronin/support/encoding/base16/core_ext/string.rb', line 39 def base16_encode Ronin::Support::Encoding::Base16.encode(self) end |
#base32_decode ⇒ String
Base32 decodes the String.
59 60 61 |
# File 'lib/ronin/support/encoding/base32/core_ext/string.rb', line 59 def base32_decode Ronin::Support::Encoding::Base32.decode(self) end |
#base32_encode ⇒ String
Base32 encodes the String.
39 40 41 |
# File 'lib/ronin/support/encoding/base32/core_ext/string.rb', line 39 def base32_encode Ronin::Support::Encoding::Base32.encode(self) end |
#base36_decode ⇒ Integer
Base36 decodes the String.
39 40 41 |
# File 'lib/ronin/support/encoding/base36/core_ext/string.rb', line 39 def base36_decode Ronin::Support::Encoding::Base36.decode(self) end |
#base62_decode ⇒ Integer
Base62 decodes the String.
39 40 41 |
# File 'lib/ronin/support/encoding/base62/core_ext/string.rb', line 39 def base62_decode Ronin::Support::Encoding::Base62.decode(self) end |
#base64_decode(mode: nil) ⇒ String
mode
argument is only available on Ruby >= 1.9.
Base64 decodes a string.
72 73 74 |
# File 'lib/ronin/support/encoding/base64/core_ext/string.rb', line 72 def base64_decode(mode: nil) Ronin::Support::Encoding::Base64.decode(self, mode: mode) end |
#base64_encode(mode: nil) ⇒ String
Base64 encodes a string.
44 45 46 |
# File 'lib/ronin/support/encoding/base64/core_ext/string.rb', line 44 def base64_encode(mode: nil) Ronin::Support::Encoding::Base64.encode(self, mode: mode) end |
#bit_flips ⇒ Array<String> Also known as: flip_bits
Returns every bit flip of every byte in the string.
55 56 57 |
# File 'lib/ronin/support/binary/bit_flip/core_ext/string.rb', line 55 def bit_flips Ronin::Support::Binary::BitFlip::String.bit_flips(self) end |
#c_encode ⇒ String
C escapes every character in the String.
79 80 81 |
# File 'lib/ronin/support/encoding/c/core_ext/string.rb', line 79 def c_encode Ronin::Support::Encoding::C.encode(self) end |
#c_escape ⇒ String
Escapes a String for C.
39 40 41 |
# File 'lib/ronin/support/encoding/c/core_ext/string.rb', line 39 def c_escape Ronin::Support::Encoding::C.escape(self) end |
#c_string ⇒ String
Converts the String into a C string.
100 101 102 |
# File 'lib/ronin/support/encoding/c/core_ext/string.rb', line 100 def c_string Ronin::Support::Encoding::C.quote(self) end |
#c_unescape ⇒ String Also known as: c_decode
Unescapes a C escaped String.
59 60 61 |
# File 'lib/ronin/support/encoding/c/core_ext/string.rb', line 59 def c_unescape Ronin::Support::Encoding::C.unescape(self) end |
#c_unquote ⇒ String
Removes the quotes an unescapes a C string.
121 122 123 |
# File 'lib/ronin/support/encoding/c/core_ext/string.rb', line 121 def c_unquote Ronin::Support::Encoding::C.unquote(self) end |
#common_prefix(other) ⇒ String
The common prefix of the string and the specified other string.
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/ronin/support/core_ext/string.rb', line 169 def common_prefix(other) min_length = [length, other.length].min min_length.times do |i| if self[i] != other[i] return self[0,i] end end return self[0,min_length] end |
#common_suffix(other) ⇒ String
Finds the common suffix of the string and the specified other string.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/ronin/support/core_ext/string.rb', line 194 def common_suffix(other) min_length = [length, other.length].min (min_length - 1).times do |i| index = (length - i - 1) other_index = (other.length - i - 1) if self[index] != other[other_index] return self[(index + 1)..] end end return '' end |
#decrypt(cipher, **kwargs) ⇒ String
Decrypts the String.
208 209 210 211 212 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 208 def decrypt(cipher,**kwargs) Ronin::Support::Crypto.decrypt(self, cipher: cipher, direction: :decrypt, **kwargs) end |
#each_bit_flip {|string| ... } ⇒ Enumerator
Enumerates over every bit flip of every byte in the string.
40 41 42 |
# File 'lib/ronin/support/binary/bit_flip/core_ext/string.rb', line 40 def each_bit_flip(&block) Ronin::Support::Binary::BitFlip::String.each_bit_flip(self,&block) end |
#each_homoglyph(**kwargs) {|homoglyph| ... } ⇒ Enumerator
Enumerates over every homoglyph variation of the String.
The character set to use.
86 87 88 |
# File 'lib/ronin/support/text/homoglyph/core_ext/string.rb', line 86 def each_homoglyph(**kwargs,&block) Ronin::Support::Text::Homoglyph.each_substitution(self,**kwargs,&block) end |
#each_substring(min = 1) {|substring, (index)| ... } ⇒ String
Enumerates over every sub-string within the string.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ronin/support/core_ext/string.rb', line 92 def each_substring(min=1,&block) return enum_for(__method__,min) unless block (0..(length - min)).each do |i| ((i + min)..length).each do |j| sub_string = self[i...j] if block.arity == 2 block.call(sub_string,i) else block.call(sub_string) end end end return self end |
#each_typo(**kwargs) {|typoed| ... } ⇒ Enumerator
Enumerates over every typo mistake for the String.
97 98 99 |
# File 'lib/ronin/support/text/typo/core_ext/string.rb', line 97 def each_typo(**kwargs,&block) Ronin::Support::Text::Typo.each_substitution(self,**kwargs,&block) end |
#each_unique_substring(min = 1) {|substring, (index)| ... } ⇒ String
Enumerates over the unique sub-strings contained in the string.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/ronin/support/core_ext/string.rb', line 138 def each_unique_substring(min=1,&block) return enum_for(__method__,min) unless block unique_strings = {} each_substring(min) do |sub_string,index| unless unique_strings.has_key?(sub_string) unique_strings[sub_string] = index if block.arity == 2 block.call(sub_string,index) else block.call(sub_string) end end end return self end |
#encode_bytes(include: nil, exclude: nil) {|byte| ... } ⇒ String
Creates a new String by formatting each byte.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ronin/support/encoding/core_ext/string.rb', line 48 def encode_bytes(include: nil, exclude: nil) included = (Chars::CharSet.new(*include) if include) excluded = (Chars::CharSet.new(*exclude) if exclude) formatted = String.new(encoding: ::Encoding::UTF_8) each_byte do |b| formatted << if (included.nil? || included.include_byte?(b)) && (excluded.nil? || !excluded.include_byte?(b)) yield(b) else b end end return formatted end |
#encode_chars(include: nil, exclude: nil) {|char| ... } ⇒ String
Creates a new String by formatting each character.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ronin/support/encoding/core_ext/string.rb', line 90 def encode_chars(include: nil, exclude: nil) included = (Chars::CharSet.new(*include) if include) excluded = (Chars::CharSet.new(*exclude) if exclude) formatted = String.new(encoding: ::Encoding::UTF_8) each_char do |c| formatted << if (included.nil? || included.include_char?(c)) && (excluded.nil? || !excluded.include_char?(c)) yield(c) else c end end return formatted end |
#encrypt(cipher, **kwargs) ⇒ String
Encrypts the String.
165 166 167 168 169 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 165 def encrypt(cipher,**kwargs) Ronin::Support::Crypto.encrypt(self, cipher: cipher, direction: :encrypt, **kwargs) end |
#entropy(**kwargs) ⇒ Float
Calculates the entropy for the given string.
41 42 43 |
# File 'lib/ronin/support/text/entropy/core_ext/string.rb', line 41 def entropy(**kwargs) Ronin::Support::Text::Entropy.calculate(self,**kwargs) end |
#gunzip ⇒ String
Gzip uncompresses the string.
71 72 73 74 75 |
# File 'lib/ronin/support/compression/core_ext/string.rb', line 71 def gunzip gz = Ronin::Support::Compression::Gzip::Reader.new(self) return gz.read end |
#gzip ⇒ String
Gzip compresses the string.
91 92 93 94 95 96 97 98 99 |
# File 'lib/ronin/support/compression/core_ext/string.rb', line 91 def gzip buffer = StringIO.new(encoding: Encoding::ASCII_8BIT) Ronin::Support::Compression::Gzip::Writer.wrap(buffer) do |gz| gz.write(self) end return buffer.string end |
#hex_decode ⇒ String
Hex-decodes the String.
53 54 55 |
# File 'lib/ronin/support/encoding/hex/core_ext/string.rb', line 53 def hex_decode Ronin::Support::Encoding::Hex.decode(self) end |
#hex_encode ⇒ String
Hex-encodes characters in the String.
37 38 39 |
# File 'lib/ronin/support/encoding/hex/core_ext/string.rb', line 37 def hex_encode Ronin::Support::Encoding::Hex.encode(self) end |
#hex_escape ⇒ String
Hex-escapes the characters within the String.
71 72 73 |
# File 'lib/ronin/support/encoding/hex/core_ext/string.rb', line 71 def hex_escape Ronin::Support::Encoding::Hex.escape(self) end |
#hex_string ⇒ String
Converts the String into a double-quoted hex string.
108 109 110 |
# File 'lib/ronin/support/encoding/hex/core_ext/string.rb', line 108 def hex_string Ronin::Support::Encoding::Hex.quote(self) end |
#hex_unescape ⇒ String
Unescapes the characters within the String.
89 90 91 |
# File 'lib/ronin/support/encoding/hex/core_ext/string.rb', line 89 def hex_unescape Ronin::Support::Encoding::Hex.unescape(self) end |
#hex_unquote ⇒ String
Removes the quotes and unescapes a hex string.
129 130 131 |
# File 'lib/ronin/support/encoding/hex/core_ext/string.rb', line 129 def hex_unquote Ronin::Support::Encoding::Hex.unquote(self) end |
#hmac(key:, digest: :sha1) ⇒ String
Calculates the HMAC of the String.
123 124 125 126 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 123 def hmac(key: , digest: :sha1) hmac = Ronin::Support::Crypto.hmac(self, key: key, digest: digest) return hmac.hexdigest end |
#homoglyph(**kwargs) ⇒ String
Returns a random homoglyph substitution of the String.
The character set to use.
52 53 54 |
# File 'lib/ronin/support/text/homoglyph/core_ext/string.rb', line 52 def homoglyph(**kwargs) Ronin::Support::Text::Homoglyph.substitute(self,**kwargs) end |
#homoglyphs(**kwargs) {|homoglyph| ... } ⇒ Array<String>
Returns every homoglyph variation of the String.
The character set to use.
137 138 139 |
# File 'lib/ronin/support/text/homoglyph/core_ext/string.rb', line 137 def homoglyphs(**kwargs) Ronin::Support::Text::Homoglyph.each_substitution(self,**kwargs).to_a end |
#html_encode(**kwargs) ⇒ String
Encodes the chars in the String for HTML.
124 125 126 |
# File 'lib/ronin/support/encoding/html/core_ext/string.rb', line 124 def html_encode(**kwargs) Ronin::Support::Encoding::HTML.encode(self,**kwargs) end |
#html_escape(**kwargs) ⇒ String
HTML escapes the String.
54 55 56 |
# File 'lib/ronin/support/encoding/html/core_ext/string.rb', line 54 def html_escape(**kwargs) Ronin::Support::Encoding::HTML.escape(self,**kwargs) end |
#html_unescape ⇒ String Also known as: html_decode
Unescapes the HTML encoded String.
75 76 77 |
# File 'lib/ronin/support/encoding/html/core_ext/string.rb', line 75 def html_unescape Ronin::Support::Encoding::HTML.unescape(self) end |
#http_decode ⇒ String
HTTP decodes the HTTP encoded String.
125 126 127 |
# File 'lib/ronin/support/encoding/http/core_ext/string.rb', line 125 def http_decode Ronin::Support::Encoding::HTTP.decode(self) end |
#http_encode(**kwargs) ⇒ String
HTTP encodes each byte of the String.
107 108 109 |
# File 'lib/ronin/support/encoding/http/core_ext/string.rb', line 107 def http_encode(**kwargs) Ronin::Support::Encoding::HTTP.encode(self,**kwargs) end |
#http_escape(**kwargs) ⇒ String
HTTP escapes the String.
53 54 55 |
# File 'lib/ronin/support/encoding/http/core_ext/string.rb', line 53 def http_escape(**kwargs) Ronin::Support::Encoding::HTTP.escape(self,**kwargs) end |
#http_unescape ⇒ String
HTTP unescapes the String.
73 74 75 |
# File 'lib/ronin/support/encoding/http/core_ext/string.rb', line 73 def http_unescape Ronin::Support::Encoding::HTTP.unescape(self) end |
#insert_after(pattern, data) ⇒ String
Inserts data after the occurrence of a pattern.
264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/ronin/support/core_ext/string.rb', line 264 def insert_after(pattern,data) string = dup match = string.match(pattern) if match index = match.end(match.length - 1) string.insert(index,data) end return string end |
#insert_before(pattern, data) ⇒ String
Inserts data before the occurrence of a pattern.
242 243 244 245 246 247 248 |
# File 'lib/ronin/support/core_ext/string.rb', line 242 def insert_before(pattern,data) string = dup index = string.index(pattern) string.insert(index,data) if index return string end |
#js_encode ⇒ String
JavaScript escapes every character of the String.
79 80 81 |
# File 'lib/ronin/support/encoding/js/core_ext/string.rb', line 79 def js_encode Ronin::Support::Encoding::JS.encode(self) end |
#js_escape ⇒ String
Escapes a String for JavaScript.
39 40 41 |
# File 'lib/ronin/support/encoding/js/core_ext/string.rb', line 39 def js_escape Ronin::Support::Encoding::JS.escape(self) end |
#js_string ⇒ String
Converts the String into a JavaScript string.
100 101 102 |
# File 'lib/ronin/support/encoding/js/core_ext/string.rb', line 100 def js_string Ronin::Support::Encoding::JS.quote(self) end |
#js_unescape ⇒ String Also known as: js_decode
Unescapes a JavaScript escaped String.
59 60 61 |
# File 'lib/ronin/support/encoding/js/core_ext/string.rb', line 59 def js_unescape Ronin::Support::Encoding::JS.unescape(self) end |
#js_unquote ⇒ String
Removes the quotes an unescapes a JavaScript string.
121 122 123 |
# File 'lib/ronin/support/encoding/js/core_ext/string.rb', line 121 def js_unquote Ronin::Support::Encoding::JS.unquote(self) end |
#md5 ⇒ String
Returns The MD5 checksum of the String.
35 36 37 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 35 def md5 Digest::MD5.hexdigest(self) end |
#pad(padding, length) ⇒ String
Creates a new String by padding the String with repeating text, out to a specified length.
296 297 298 |
# File 'lib/ronin/support/core_ext/string.rb', line 296 def pad(padding,length) ljust(length,padding) end |
#powershell_encode ⇒ String Also known as: psh_encode
PowerShell encodes every character in the String.
89 90 91 |
# File 'lib/ronin/support/encoding/powershell/core_ext/string.rb', line 89 def powershell_encode Ronin::Support::Encoding::PowerShell.encode(self) end |
#powershell_escape ⇒ String Also known as: psh_escape
PowerShell escapes the characters in the String.
41 42 43 |
# File 'lib/ronin/support/encoding/powershell/core_ext/string.rb', line 41 def powershell_escape Ronin::Support::Encoding::PowerShell.escape(self) end |
#powershell_string ⇒ String Also known as: psh_string
Converts the String into a double-quoted PowerShell escaped String.
114 115 116 |
# File 'lib/ronin/support/encoding/powershell/core_ext/string.rb', line 114 def powershell_string Ronin::Support::Encoding::PowerShell.quote(self) end |
#powershell_unescape ⇒ String Also known as: psh_unescape, powershell_decode
PowerShell unescapes the characters in the String.
65 66 67 |
# File 'lib/ronin/support/encoding/powershell/core_ext/string.rb', line 65 def powershell_unescape Ronin::Support::Encoding::PowerShell.unescape(self) end |
#powershell_unquote ⇒ String Also known as: psh_unquote
Removes the quotes an unescapes a PowerShell string.
139 140 141 |
# File 'lib/ronin/support/encoding/powershell/core_ext/string.rb', line 139 def powershell_unquote Ronin::Support::Encoding::PowerShell.unquote(self) end |
#punycode_decode ⇒ String
Decodes a punycode String back into unicode.
59 60 61 |
# File 'lib/ronin/support/encoding/punycode/core_ext/string.rb', line 59 def punycode_decode Ronin::Support::Encoding::Punycode.decode(self) end |
#punycode_encode ⇒ String
Encodes a unicode String into punycode.
39 40 41 |
# File 'lib/ronin/support/encoding/punycode/core_ext/string.rb', line 39 def punycode_encode Ronin::Support::Encoding::Punycode.encode(self) end |
#quoted_printable_escape ⇒ String Also known as: quoted_printable_encode, qp_escape, qp_encode
Escapes the String as Quoted-Printable.
41 42 43 |
# File 'lib/ronin/support/encoding/quoted_printable/core_ext/string.rb', line 41 def quoted_printable_escape Ronin::Support::Encoding::QuotedPrintable.escape(self) end |
#quoted_printable_unescape ⇒ String Also known as: quoted_printable_decode, qp_decode, qp_unescape
Unescapes a Quoted-Printable encoded String.
67 68 69 |
# File 'lib/ronin/support/encoding/quoted_printable/core_ext/string.rb', line 67 def quoted_printable_unescape Ronin::Support::Encoding::QuotedPrintable.unescape(self) end |
#random_case ⇒ String
Creates a new String by randomizing the case of each character in the String.
42 43 44 |
# File 'lib/ronin/support/text/core_ext/string.rb', line 42 def random_case Ronin::Support::Text::Random.swapcase(self) end |
#rmd160 ⇒ String
JRuby and TruffleRuby do not yet support RMD160.
Calculates the RMD160 checksum for the String.
101 102 103 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 101 def rmd160 Digest::RMD160.hexdigest(self) end |
#rot(n = 13, **kwargs) ⇒ String
This method was added as a joke and should not be used for secure cryptographic communications.
Rotates the characters in the string using the given alphabet.
551 552 553 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 551 def rot(n=13,**kwargs) Ronin::Support::Crypto.rot(self,n,**kwargs) end |
#rsa_decrypt(**kwargs) ⇒ String
Decrypts the String using the given RSA key.
Optional padding mode. nil
and false
will disable padding.
518 519 520 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 518 def rsa_decrypt(**kwargs) Ronin::Support::Crypto.rsa_decrypt(self,**kwargs) end |
#rsa_encrypt(**kwargs) ⇒ String
Encrypts the String using the given RSA key.
Optional padding mode. nil
and false
will disable padding.
487 488 489 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 487 def rsa_encrypt(**kwargs) Ronin::Support::Crypto.rsa_encrypt(self,**kwargs) end |
#ruby_encode ⇒ String
Ruby escapes every character in the String.
83 84 85 |
# File 'lib/ronin/support/encoding/ruby/core_ext/string.rb', line 83 def ruby_encode Ronin::Support::Encoding::Ruby.encode(self) end |
#ruby_escape ⇒ String Also known as: escape
Escapes a String for Ruby.
39 40 41 |
# File 'lib/ronin/support/encoding/ruby/core_ext/string.rb', line 39 def ruby_escape Ronin::Support::Encoding::Ruby.escape(self) end |
#ruby_string ⇒ String
Rubyonverts the String into a Ruby string.
104 105 106 |
# File 'lib/ronin/support/encoding/ruby/core_ext/string.rb', line 104 def ruby_string Ronin::Support::Encoding::Ruby.quote(self) end |
#ruby_unescape ⇒ String Also known as: unescape, ruby_decode
Unescapes a Ruby escaped String.
61 62 63 |
# File 'lib/ronin/support/encoding/ruby/core_ext/string.rb', line 61 def ruby_unescape Ronin::Support::Encoding::Ruby.unescape(self) end |
#ruby_unquote ⇒ String
Removes the quotes an unescapes a Ruby string.
125 126 127 |
# File 'lib/ronin/support/encoding/ruby/core_ext/string.rb', line 125 def ruby_unquote Ronin::Support::Encoding::Ruby.unquote(self) end |
#sha1 ⇒ String Also known as: sha128
Returns The SHA1 checksum of the String.
49 50 51 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 49 def sha1 Digest::SHA1.hexdigest(self) end |
#sha256 ⇒ String Also known as: sha2
Returns The SHA256 checksum of the String.
65 66 67 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 65 def sha256 Digest::SHA256.hexdigest(self) end |
#sha512 ⇒ String
Returns The SHA512 checksum of the String.
81 82 83 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 81 def sha512 Digest::SHA512.hexdigest(self) end |
#shell_encode ⇒ String
Shell encodes every character in the String.
81 82 83 |
# File 'lib/ronin/support/encoding/shell/core_ext/string.rb', line 81 def shell_encode Ronin::Support::Encoding::Shell.encode(self) end |
#shell_escape ⇒ String
Shell escapes the characters in the String.
41 42 43 |
# File 'lib/ronin/support/encoding/shell/core_ext/string.rb', line 41 def shell_escape Ronin::Support::Encoding::Shell.escape(self) end |
#shell_string ⇒ String
Converts the String into a double-quoted shell escaped String.
105 106 107 |
# File 'lib/ronin/support/encoding/shell/core_ext/string.rb', line 105 def shell_string Ronin::Support::Encoding::Shell.quote(self) end |
#shell_unescape ⇒ String Also known as: shell_decode
Shell unescapes the characters in the String.
61 62 63 |
# File 'lib/ronin/support/encoding/shell/core_ext/string.rb', line 61 def shell_unescape Ronin::Support::Encoding::Shell.unescape(self) end |
#shell_unquote ⇒ String
Removes the quotes an unescapes a shell string.
130 131 132 |
# File 'lib/ronin/support/encoding/shell/core_ext/string.rb', line 130 def shell_unquote Ronin::Support::Encoding::Shell.unquote(self) end |
#sql_decode ⇒ Object
Returns the SQL decoded form of the String.
110 111 112 |
# File 'lib/ronin/support/encoding/sql/core_ext/string.rb', line 110 def sql_decode Ronin::Support::Encoding::SQL.decode(self) end |
#sql_encode ⇒ Object
Returns the SQL hex-string encoded form of the String.
88 89 90 |
# File 'lib/ronin/support/encoding/sql/core_ext/string.rb', line 88 def sql_encode Ronin::Support::Encoding::SQL.encode(self) end |
#sql_escape(**kwargs) ⇒ String
Escapes an String for SQL.
50 51 52 |
# File 'lib/ronin/support/encoding/sql/core_ext/string.rb', line 50 def sql_escape(**kwargs) Ronin::Support::Encoding::SQL.escape(self,**kwargs) end |
#sql_unescape ⇒ String
Unescapes a SQL String.
73 74 75 |
# File 'lib/ronin/support/encoding/sql/core_ext/string.rb', line 73 def sql_unescape Ronin::Support::Encoding::SQL.unescape(self) end |
#to_ascii ⇒ String
Converts the string into an ASCII encoded string.
48 49 50 |
# File 'lib/ronin/support/core_ext/string.rb', line 48 def to_ascii encode(Encoding::ASCII_8BIT) end |
#to_utf8 ⇒ String
Converts the string into an UTF-8 encoded string.
62 63 64 |
# File 'lib/ronin/support/core_ext/string.rb', line 62 def to_utf8 encode(Encoding::UTF_8) end |
#typo(**kwargs) ⇒ String
Returns a random typo substitution for the String.
54 55 56 |
# File 'lib/ronin/support/text/typo/core_ext/string.rb', line 54 def typo(**kwargs) Ronin::Support::Text::Typo.substitute(self,**kwargs) end |
#typos(**kwargs) ⇒ Array<String>
Returns every typo for the String.
143 144 145 |
# File 'lib/ronin/support/text/typo/core_ext/string.rb', line 143 def typos(**kwargs) Ronin::Support::Text::Typo.each_substitution(self,**kwargs).to_a end |
#uncommon_substring(other) ⇒ String
Finds the uncommon sub-string within the specified other string, which does not occur within the string.
221 222 223 224 225 226 |
# File 'lib/ronin/support/core_ext/string.rb', line 221 def uncommon_substring(other) prefix = common_prefix(other) postfix = self[prefix.length..].common_suffix(other[prefix.length..]) return self[prefix.length...(length - postfix.length)] end |
#unhexdump(**kwargs) ⇒ String
Converts a multitude of hexdump formats back into raw-data.
122 123 124 125 |
# File 'lib/ronin/support/binary/unhexdump/core_ext/string.rb', line 122 def unhexdump(**kwargs) parser = Ronin::Support::Binary::Unhexdump::Parser.new(**kwargs) parser.unhexdump(self) end |
#unpack(*arguments, **kwargs) ⇒ Array
Unpacks the String.
The desired architecture that the data was packed for.
The Operating System (OS) to use.
73 74 75 76 77 78 79 80 |
# File 'lib/ronin/support/binary/core_ext/string.rb', line 73 def unpack(*arguments,**kwargs) if (arguments.length == 1 && arguments.first.kind_of?(String)) unpack_original(arguments.first) else template = Ronin::Support::Binary::Template.new(arguments,**kwargs) template.unpack(self) end end |
#unpack1(argument, **kwargs) ⇒ Integer, ...
Unpacks a single value from the String.
The desired architecture that the data was packed for.
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ronin/support/binary/core_ext/string.rb', line 114 def unpack1(argument,**kwargs) case argument when String unpack1_original(argument) when Symbol platform = Ronin::Support::Binary::CTypes.platform(**kwargs) type = platform[argument] unpack1_original(type.pack_string) else raise(ArgumentError,"argument must be either a String or a Symbol: #{argument.inspect}") end end |
#unpack1_original ⇒ Object
82 |
# File 'lib/ronin/support/binary/core_ext/string.rb', line 82 alias unpack1_original unpack1 |
#unpack_original ⇒ Object
25 |
# File 'lib/ronin/support/binary/core_ext/string.rb', line 25 alias unpack_original unpack |
#uri_encode(**kwargs) ⇒ String
URI encodes the String.
95 96 97 |
# File 'lib/ronin/support/encoding/uri/core_ext/string.rb', line 95 def uri_encode(**kwargs) Ronin::Support::Encoding::URI.encode(self,**kwargs) end |
#uri_escape(**kwargs) ⇒ String
URI escapes the String.
48 49 50 |
# File 'lib/ronin/support/encoding/uri/core_ext/string.rb', line 48 def uri_escape(**kwargs) Ronin::Support::Encoding::URI.escape(self,**kwargs) end |
#uri_form_encode(**kwargs) ⇒ String Also known as: www_form_encode
URI Form encodes every character in the String.
186 187 188 |
# File 'lib/ronin/support/encoding/uri/core_ext/string.rb', line 186 def uri_form_encode(**kwargs) Ronin::Support::Encoding::URI::Form.encode(self,**kwargs) end |
#uri_form_escape(**kwargs) ⇒ String Also known as: www_form_escape
URI Form escapes the String.
131 132 133 |
# File 'lib/ronin/support/encoding/uri/core_ext/string.rb', line 131 def uri_form_escape(**kwargs) Ronin::Support::Encoding::URI::Form.escape(self,**kwargs) end |
#uri_form_unescape ⇒ String Also known as: www_form_unescape, uri_form_decode
URI Form unescapes the String.
153 154 155 |
# File 'lib/ronin/support/encoding/uri/core_ext/string.rb', line 153 def uri_form_unescape Ronin::Support::Encoding::URI::Form.unescape(self) end |
#uri_unescape ⇒ String Also known as: uri_decode
URI unescapes the String.
66 67 68 |
# File 'lib/ronin/support/encoding/uri/core_ext/string.rb', line 66 def uri_unescape Ronin::Support::Encoding::URI.unescape(self) end |
#uu_decode ⇒ String Also known as: uudecode, uu_unescape
Decodes the uuencoded String.
66 67 68 |
# File 'lib/ronin/support/encoding/uuencoding/core_ext/string.rb', line 66 def uu_decode Ronin::Support::Encoding::UUEncoding.decode(self) end |
#uu_encode ⇒ String Also known as: uuencode, uu_escape
uuencodes the String.
41 42 43 |
# File 'lib/ronin/support/encoding/uuencoding/core_ext/string.rb', line 41 def uu_encode Ronin::Support::Encoding::UUEncoding.encode(self) end |
#xml_encode(**kwargs) ⇒ String
Encodes each character in the String as an XML character.
118 119 120 |
# File 'lib/ronin/support/encoding/xml/core_ext/string.rb', line 118 def xml_encode(**kwargs) Ronin::Support::Encoding::XML.encode(self,**kwargs) end |
#xml_escape(**kwargs) ⇒ String
XML escapes the String.
51 52 53 |
# File 'lib/ronin/support/encoding/xml/core_ext/string.rb', line 51 def xml_escape(**kwargs) Ronin::Support::Encoding::XML.escape(self,**kwargs) end |
#xml_unescape ⇒ String Also known as: xml_decode
Unescapes the XML encoded String.
72 73 74 |
# File 'lib/ronin/support/encoding/xml/core_ext/string.rb', line 72 def xml_unescape Ronin::Support::Encoding::XML.unescape(self) end |
#xor(key) ⇒ String Also known as: ^
XOR encodes the String.
574 575 576 |
# File 'lib/ronin/support/crypto/core_ext/string.rb', line 574 def xor(key) Ronin::Support::Crypto.xor(self,key) end |
#zlib_deflate ⇒ String
Zlib deflate a string.
53 54 55 |
# File 'lib/ronin/support/compression/core_ext/string.rb', line 53 def zlib_deflate Ronin::Support::Compression.zlib_deflate(self) end |
#zlib_inflate ⇒ String
Zlib inflate a string.
37 38 39 |
# File 'lib/ronin/support/compression/core_ext/string.rb', line 37 def zlib_inflate Ronin::Support::Compression.zlib_inflate(self) end |