Class: RCrypto::CustomEncryptor
- Inherits:
-
Object
- Object
- RCrypto::CustomEncryptor
- Defined in:
- lib/RCrypto.rb
Class Method Summary collapse
-
.decrypt(encrypted_text_with_key) ⇒ Object
Decrypts the given encrypted text using the same steps in reverse.
-
.encrypt(text) ⇒ Object
Encrypts the given text using a series of encryption steps.
-
.generate_key ⇒ Object
Generates a random key using MD5 hash.
Class Method Details
.decrypt(encrypted_text_with_key) ⇒ Object
Decrypts the given encrypted text using the same steps in reverse
24 25 26 27 28 29 30 31 |
# File 'lib/RCrypto.rb', line 24 def self.decrypt(encrypted_text_with_key) encrypted_text, key = encrypted_text_with_key.split("#", 2) stage4 = Decode.remove_fake_token(encrypted_text) stage3 = Decode.caesar_cipher_decrypt(stage4, key.bytes.sum % 26) stage2 = Decode.base64_custom_decode(stage3) original_text = Decode.xor_decrypt(stage2, key[0..15]) original_text end |
.encrypt(text) ⇒ Object
Encrypts the given text using a series of encryption steps
13 14 15 16 17 18 19 20 21 |
# File 'lib/RCrypto.rb', line 13 def self.encrypt(text) key = generate_key stage1 = Encode.xor_encrypt(text, key[0..15]) stage2 = Encode.base64_custom_encode(stage1) stage3 = Encode.caesar_cipher_encrypt(stage2, key.bytes.sum % 26) stage4 = Encode.add_fake_token(stage3) final_encrypted = stage4 + "#" + key final_encrypted end |
.generate_key ⇒ Object
Generates a random key using MD5 hash
34 35 36 |
# File 'lib/RCrypto.rb', line 34 def self.generate_key Digest::MD5.hexdigest(SecureRandom.bytes(16)) end |