Class: EnigmaEncrypto::Cracker
- Inherits:
-
Object
- Object
- EnigmaEncrypto::Cracker
- Defined in:
- lib/enigma_encrypto/cracker.rb
Instance Method Summary collapse
- #creating_key ⇒ Object
- #get_key ⇒ Object
-
#initialize(file, length, offset) ⇒ Cracker
constructor
A new instance of Cracker.
- #locate_position_to_start_crack ⇒ Object
- #needed_four_of_file ⇒ Object
- #the_end_arr ⇒ Object
Constructor Details
#initialize(file, length, offset) ⇒ Cracker
Returns a new instance of Cracker.
8 9 10 11 12 13 |
# File 'lib/enigma_encrypto/cracker.rb', line 8 def initialize(file, length, offset) @offset = offset @file = file @length = length @character_map = Rotator.new.character_map_creation end |
Instance Method Details
#creating_key ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/enigma_encrypto/cracker.rb', line 34 def creating_key key_arr = [] 4.times do |index| key_arr << @text_arr[index] - @offset[index] - @end_arr[@end_index] @end_index += 1 end key_arr end |
#get_key ⇒ Object
43 44 45 46 47 48 |
# File 'lib/enigma_encrypto/cracker.rb', line 43 def get_key locate_position_to_start_crack needed_four_of_file the_end_arr creating_key end |
#locate_position_to_start_crack ⇒ Object
15 16 17 18 19 |
# File 'lib/enigma_encrypto/cracker.rb', line 15 def locate_position_to_start_crack seek_pt = @length % 4 @file.seek(@length - (4 + seek_pt)) @end_index = 3 - seek_pt end |
#needed_four_of_file ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/enigma_encrypto/cracker.rb', line 21 def needed_four_of_file @text_arr = [] 4.times do @text_arr << @file.getc end @text_arr.map!{|letter| @character_map.index(letter)} end |
#the_end_arr ⇒ Object
29 30 31 32 |
# File 'lib/enigma_encrypto/cracker.rb', line 29 def the_end_arr @end_arr = [".", ".", "e", "n", "d", ".", "."] @end_arr.map!{|letter| @character_map.index(letter)} end |