andela-gogbara/Enigma

View on GitHub
bin/crack

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby

require "enigma"

if ARGV.length < 2 || ARGV.length > 3
  puts "Incorrect number of argument."
elsif !File.file?(ARGV[0])
  puts "The input file path does not exist."
elsif ARGV.length == 3 && File.file?(ARGV[1])
  puts "The output file path file already exist. Do you want to overwrite it? yes/no"
  user_choice = STDIN.gets.chomp
  if user_choice == "yes"
    ENIGMA::Crack.new(ARGV[0], ARGV[1], ARGV[2]).crack_write
    key = ENIGMA::Crack.new(ARGV[0], ARGV[1], ARGV[2]).clean_key
    puts ENIGMA::Messages.success_message(ARGV[1], key, ARGV[2])
  else
    puts "Cant continue with cracking"
  end
else
  ENIGMA::Crack.new(ARGV[0], ARGV[1], ARGV[2]).crack_write
  key = ENIGMA::Crack.new(ARGV[0], ARGV[1], ARGV[2]).clean_key
  puts ENIGMA::Messages.success_message(ARGV[1], key, ARGV[2])
end