Module: StringTransformer
- Included in:
- String
- Defined in:
- lib/string_transformer.rb,
lib/string_transformer/version.rb
Constant Summary collapse
- VERSION =
"1.0.0"- @@key =
nil- @@encrypt =
""- @@original_str =
""
Instance Method Summary collapse
-
#decrypt ⇒ Object
If @@key includes a key that is the same as the given string(encrypted string) then it will decrypt the string(return original string that was save as the value).
-
#encrypt ⇒ Object
The method encrypt replaces every character in a given string with the first 4 elements in encryption_arr.
-
#encryption_arr ⇒ Object
The method encryption_arr returns an array of characters that will replace each letter in a given string.
Instance Method Details
#decrypt ⇒ Object
If @@key includes a key that is the same as the given string(encrypted string) then it will decrypt the string(return original string that was save as the value)
24 25 26 27 28 29 30 31 |
# File 'lib/string_transformer.rb', line 24 def decrypt decrypt_str = self if @@key.keys.include?(decrypt_str) @@key[@@encrypt] else "Error! Can't decrypt. The string is not valid." end end |
#encrypt ⇒ Object
The method encrypt replaces every character in a given string with the first 4 elements in encryption_arr
15 16 17 18 19 20 |
# File 'lib/string_transformer.rb', line 15 def encrypt @@original_str = self @@encrypt = @@original_str.split("").map { |letter| letter.replace(encryption_arr.shuffle.first(4).join) }.join @@key = encryption_key(@@encrypt, @@original_str) @@encrypt end |
#encryption_arr ⇒ Object
The method encryption_arr returns an array of characters that will replace each letter in a given string
9 10 11 12 |
# File 'lib/string_transformer.rb', line 9 def encryption_arr encryption_string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*+><?1234567890" encryption_string.split("") end |