class Enygma::Cracker
Constants
- PLAIN_LAST_7_CHARACTERS
Public Class Methods
new(cypher_filename, encryption_date, plain_filename = nil)
click to toggle source
# File lib/enygma/cracker.rb, line 11 def initialize(cypher_filename, encryption_date, plain_filename = nil) @cypher_filename = cypher_filename @plain_filename = plain_filename @encryption_date = encryption_date @offset = Offset.get_offset(@encryption_date) @decrypted = "" end
Public Instance Methods
crack()
click to toggle source
# File lib/enygma/cracker.rb, line 19 def crack cypher_characters = Filer.read(@cypher_filename) cypher_last_4_characters = cypher_characters.last(4) cypher_last_4_characters.rotate!(4 - (cypher_characters.size % 4)) plain_last_4_characters = PLAIN_LAST_7_CHARACTERS.split("").last(4) plain_last_4_characters.rotate!(4 - (cypher_characters.size % 4)) offset_characters = @offset.split("") differences = get_differences( cypher_last_4_characters, plain_last_4_characters, offset_characters ) key = KeyGen.get_key(differences) Decryptor.new(@cypher_filename, key, @encryption_date, @plain_filename). decrypt end
get_differences(cypher_array, plain_array, offset_array)
click to toggle source
# File lib/enygma/cracker.rb, line 37 def get_differences(cypher_array, plain_array, offset_array) differences = [] 4.times do |i| diff = Enygma::CHARACTER_MAP.index(cypher_array[i]) - Enygma::CHARACTER_MAP.index(plain_array[i]) diff -= offset_array[i].to_i differences[i] = diff.to_s.rjust(2, '0') end differences end