Module: EnigmaHelpers

Included in:
Decryption, ENIGMA::PossibleKeys, Encryption
Defined in:
lib/enigma/enigmahelpers.rb

Instance Method Summary collapse

Instance Method Details

#character_mapObject



2
3
4
# File 'lib/enigma/enigmahelpers.rb', line 2

def character_map
  [*"a".."z"] + [*"0".."9"] + [".", ",", " "]
end

#date_of_encryptionObject



28
29
30
31
# File 'lib/enigma/enigmahelpers.rb', line 28

def date_of_encryption
  dd = Time.now
  "#{format_month(dd.day)}#{format_month(dd.month)}#{dd.year.to_s[-2..-1]}".to_i
end

#format_month(month) ⇒ Object



24
25
26
# File 'lib/enigma/enigmahelpers.rb', line 24

def format_month(month)
  month < 10 ? "0" << month.to_s : month
end

#generate_keyObject



6
7
8
# File 'lib/enigma/enigmahelpers.rb', line 6

def generate_key
  [*1..9].sample(5).join("")
end

#key_rotation(count, key) ⇒ Object



14
15
16
17
# File 'lib/enigma/enigmahelpers.rb', line 14

def key_rotation(count, key)
  shift = count % 4
  key[shift..shift + 1].to_i
end

#offset_key(date_of_encryption) ⇒ Object



33
34
35
36
37
# File 'lib/enigma/enigmahelpers.rb', line 33

def offset_key(date_of_encryption)
  date_key = date_of_encryption.to_i
  date_key **= 2
  date_key.to_s[-4..-1]
end

#offset_rotation(count, offsetkey) ⇒ Object



19
20
21
22
# File 'lib/enigma/enigmahelpers.rb', line 19

def offset_rotation(count, offsetkey)
  shift = count % 4
  offsetkey[shift].to_i
end

#total_rotation(count, key, offsetkey) ⇒ Object



10
11
12
# File 'lib/enigma/enigmahelpers.rb', line 10

def total_rotation(count, key, offsetkey)
  key_rotation(count, key) + offset_rotation(count, offsetkey)
end