Module: OutputFile

Defined in:
lib/dgen/outputfile.rb

Overview

Provides the output file module for use as a mixin.

Class Method Summary collapse

Class Method Details

.decrypt(e_phrase, key) ⇒ Object

Decrypts a given passphrase.



28
29
30
31
32
# File 'lib/dgen/outputfile.rb', line 28

def self.decrypt(e_phrase, key)
  blowfish = Crypt::Blowfish.new(key)
  phrase = blowfish.decrypt_string(e_phrase)
  phrase
end

.encrypt(phrase, key) ⇒ Object

Encrypts a given passphrase.



19
20
21
22
23
# File 'lib/dgen/outputfile.rb', line 19

def self.encrypt(phrase, key)
  blowfish = Crypt::Blowfish.new(key)
  e_phrase = blowfish.encrypt_string(phrase)
  e_phrase
end

.open_ofile(file) ⇒ Object

Opens a previously saved output file for reading.



67
68
69
70
71
72
73
74
75
# File 'lib/dgen/outputfile.rb', line 67

def self.open_ofile(file)
  print 'Enter a key for decryption => '
  key = gets.chomp
  File.foreach(file) do |l|
    e_phrase = l.chomp
    phrase = decrypt(e_phrase, key)
    puts "Decrypted passphrase: '#{phrase}'"
  end
end

.save_batch(phrase) ⇒ Object

Saves passphrases to a file.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dgen/outputfile.rb', line 51

def self.save_batch(phrase)
  print 'Enter name for output file => '
  o_file = gets.chomp
  f = File.open("#{o_file}", 'w+')
  print 'Enter a key for encryption => '
  key = gets.chomp
  phrase.each do |p|
    e_phrase = encrypt(p, key)
    f.puts e_phrase
  end
  f.close
end

.save_pass(phrase) ⇒ Object

Saves passphrase to a file.



37
38
39
40
41
42
43
44
45
46
# File 'lib/dgen/outputfile.rb', line 37

def self.save_pass(phrase)
  print 'Enter name for output file => '
  o_file = gets.chomp
  f = File.open("#{o_file}", 'w+')
  print 'Enter a key for encryption => '
  key = gets.chomp
  e_phrase = encrypt(phrase, key)
  f.puts e_phrase
  f.close
end