Class: Ratsel::Crack

Inherits:
Object
  • Object
show all
Includes:
SendMessage
Defined in:
lib/ratsel/crack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SendMessage

#message

Constructor Details

#initialize(encrypted_txt, cracked_txt, encryption_date) ⇒ Crack

Returns a new instance of Crack.



6
7
8
9
10
11
# File 'lib/ratsel/crack.rb', line 6

def initialize(encrypted_txt, cracked_txt, encryption_date)
  @encryption_key = nil
  @encryption_date = encryption_date
  @encrypted_txt = encrypted_txt
  @cracked_txt = cracked_txt
end

Instance Attribute Details

#cracked_txtObject (readonly)

Returns the value of attribute cracked_txt.



4
5
6
# File 'lib/ratsel/crack.rb', line 4

def cracked_txt
  @cracked_txt
end

#encrypted_txtObject (readonly)

Returns the value of attribute encrypted_txt.



4
5
6
# File 'lib/ratsel/crack.rb', line 4

def encrypted_txt
  @encrypted_txt
end

#encryption_dateObject (readonly)

Returns the value of attribute encryption_date.



4
5
6
# File 'lib/ratsel/crack.rb', line 4

def encryption_date
  @encryption_date
end

#encryption_keyObject (readonly)

Returns the value of attribute encryption_key.



4
5
6
# File 'lib/ratsel/crack.rb', line 4

def encryption_key
  @encryption_key
end

Instance Method Details

#crackObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ratsel/crack.rb', line 13

def crack
  last_char = '..end..'
  encrypted_message = Ratsel::Accessor.read_file_text(encrypted_txt)

  encrypted_message_last_4 = encrypted_message.last(4)
  last_4_char = last_char.split("").last(4)
  encrypted_message_last_4.rotate!(4 - (encrypted_message.size % 4))
  last_4_char.rotate!(4 - (encrypted_message.size % 4))
  offsets = Ratsel::Helpers.offsets_array(@encryption_date)

  differences = Ratsel::Helpers.get_differences(
    encrypted_message_last_4,
    last_4_char,
    offsets
    )

  # Get the missing key
  key = Ratsel::Helpers.get_key(differences)

  # Initialize Decrypt method with the missing key
  Ratsel::Decrypt.new(encrypted_txt, cracked_txt, key, encryption_date).decrypt
end