Class: ReversibleCryptography::CLI
- Inherits:
-
Thor
- Object
- Thor
- ReversibleCryptography::CLI
- Defined in:
- lib/reversible_cryptography/cli.rb
Instance Method Summary collapse
Instance Method Details
#decrypt(encrypted_text = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/reversible_cryptography/cli.rb', line 30 def decrypt(encrypted_text=nil) encrypted_text = File.read([:src_file]) if [:src_file] encrypted_text ||= ask("Input text:") password = [:password] password ||= ask("Input password:", echo: false).tap { puts } plain_text = ReversibleCryptography::Message.decrypt(encrypted_text, password) if [:dst_file] File.open([:dst_file], "wb") do |f| f.write(plain_text) end else puts plain_text end end |
#encrypt(plain_text = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/reversible_cryptography/cli.rb', line 10 def encrypt(plain_text=nil) plain_text = File.read([:src_file]) if [:src_file] plain_text ||= ask("Input text:") password = [:password] password ||= ask("Input password:", echo: false).tap { puts } encrypted_text = ReversibleCryptography::Message.encrypt(plain_text, password) if [:dst_file] File.open([:dst_file], "wb") do |f| f.write(encrypted_text) end else puts encrypted_text end end |