Files
SecGen/lib/objects/local_hash_encoder.rb
2018-11-16 10:19:10 +00:00

70 lines
1.6 KiB
Ruby

#!/usr/bin/ruby
require_relative 'local_string_encoder.rb'
require 'digest'
class HashEncoder < StringEncoder
attr_accessor :salt
attr_accessor :return_salts
attr_accessor :salt_position
def initialize
super
self.module_name = 'Hash Encoder'
self.strings_to_encode = []
self.salt = []
self.return_salts = false
self.salt_position = %w(before after).sample
end
def hash_function(str)
end
def encode_all
self.strings_to_encode.each_with_index do |string, i|
combined_string = string
if self.salt[i]
if salt_position == 'before'
combined_string = self.salt[i] + combined_string
elsif salt_position == 'after'
combined_string = combined_string + self.salt[i]
end
end
self.outputs << hash_function(combined_string)
end
if self.return_salts
self.outputs += self.salt
end
end
def process_options(opt, arg)
super
if opt == '--salt'
self.salt << arg;
end
if opt == '--return_salts'
self.return_salts = (arg.to_s.downcase == 'true');
end
end
def get_options_array
super + [['--salt', GetoptLong::OPTIONAL_ARGUMENT],
['--return_salts', GetoptLong::OPTIONAL_ARGUMENT]]
end
def encoding_print_string
print_string = 'strings_to_encode: ' + self.strings_to_encode.to_s + print_string_padding +
'salt: ' + self.salt.to_s
if self.salt.size > 0
print_string += print_string_padding
print_string += "return_salts: #{self.return_salts.to_s} #{print_string_padding}"
print_string += "salt_position: #{self.salt_position.to_s}"
end
print_string
end
end