Skip to content

Instantly share code, notes, and snippets.

@JGallardo
Created December 13, 2012 02:29
Show Gist options
  • Save JGallardo/4273537 to your computer and use it in GitHub Desktop.
Save JGallardo/4273537 to your computer and use it in GitHub Desktop.
File encryption script written in Ruby
require 'crypt/blowfish'
unless ARGV[0]
puts "Usage: ruby encrypt.rb <filename.ext>"
puts "Example: ruby encrypt.rb secret.stuff"
exit
end
#take in the file name to encrypt as an argument
filename = ARGV[0].chomp
puts filename
c = "Endcrypted_#{filename}"
if File.exists?(c)
puts "File already exists."
exit
end
print 'Enter your encryption key (1-56 bytes): '
kee = gets.chomp
begin
blowfish = Crypt::Blowfish.new(kee)
blowfish.encrypt_file(filename.to_str, c)
puts 'Encryption SUCCESS!'
rescue Exception => e
puts "An error occurred during the encryption: \n #{e}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment