class Gemnigma::Encrypt
Public Class Methods
new()
click to toggle source
# File lib/Gemnigma/encrypt.rb, line 7 def initialize @message = Messages.new end
Public Instance Methods
get_cmd_args()
click to toggle source
# File lib/Gemnigma/encrypt.rb, line 11 def get_cmd_args if ARGV.length < 3 @message.few_args return end if ARGV.length == 3 @input_file = ARGV[1] @output_file = ARGV[2] validate { encrypt_file(@input_file, @output_file) } end if ARGV.length > 3 @message.too_much_args return end end
Private Instance Methods
encrypt_file(input, output)
click to toggle source
# File lib/Gemnigma/encrypt.rb, line 32 def encrypt_file(input, output) file_input = File.open(input, "r+") encrypted_file = File.open(output, "w+") decryption_key = File.open("#{output.sub('txt', 'secret')}", "w+") input_content = file_input.read @secret_key = rand(10000..99999) @date_gen = Offset.new.full_date encrypt = RotatorEncrypt.new(Key.new(@secret_key)) encrypted_file.write(encrypt.rot_encrypt(input_content)) decryption_key.write("Decrypt #{@output_file} with the key: #{@secret_key} and date: #{@date_gen}") file_input.close encrypted_file.close @message.success_message(@output_file, @secret_key, @date_gen) end