Class: EnigmaEncrypto::Cracker

Inherits:
Object
  • Object
show all
Defined in:
lib/enigma_encrypto/cracker.rb

Instance Method Summary collapse

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_keyObject



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_keyObject



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_crackObject



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_fileObject



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_arrObject



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