Module: RCrypto::Encode
- Defined in:
- lib/RCrypto/encode.rb
Class Method Summary collapse
- .add_fake_token(text) ⇒ Object
- .base64_custom_encode(text) ⇒ Object
- .caesar_cipher_encrypt(text, shift) ⇒ Object
- .xor_encrypt(text, key) ⇒ Object
Class Method Details
.add_fake_token(text) ⇒ Object
26 27 28 29 30 |
# File 'lib/RCrypto/encode.rb', line 26 def self.add_fake_token(text) fake_token = "$" + SecureRandom.alphanumeric(10) insertion_point = SecureRandom.random_number(text.length) text.insert(insertion_point, fake_token) end |
.base64_custom_encode(text) ⇒ Object
11 12 13 |
# File 'lib/RCrypto/encode.rb', line 11 def self.base64_custom_encode(text) Base64.strict_encode64(text) end |
.caesar_cipher_encrypt(text, shift) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/RCrypto/encode.rb', line 15 def self.caesar_cipher_encrypt(text, shift) text.chars.map do |char| if char.match(/[a-zA-Z]/) base = char =~ /[a-z]/ ? 'a'.ord : 'A'.ord ((char.ord - base + shift) % 26 + base).chr else char end end.join end |
.xor_encrypt(text, key) ⇒ Object
5 6 7 8 9 |
# File 'lib/RCrypto/encode.rb', line 5 def self.xor_encrypt(text, key) text.bytes.map.with_index do |byte, i| (byte ^ key.bytes[i % key.length]).chr end.join end |