Class: CryptoToolchain::Tools::AesCtrRecoverer

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto_toolchain/tools/aes_ctr_recoverer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(editor) ⇒ AesCtrRecoverer

Returns a new instance of AesCtrRecoverer.



7
8
9
10
# File 'lib/crypto_toolchain/tools/aes_ctr_recoverer.rb', line 7

def initialize(editor)
  @editor = editor
  @ciphertext = editor.ciphertext
end

Instance Attribute Details

#ciphertextObject (readonly)

Returns the value of attribute ciphertext.



5
6
7
# File 'lib/crypto_toolchain/tools/aes_ctr_recoverer.rb', line 5

def ciphertext
  @ciphertext
end

#editorObject (readonly)

Returns the value of attribute editor.



5
6
7
# File 'lib/crypto_toolchain/tools/aes_ctr_recoverer.rb', line 5

def editor
  @editor
end

Instance Method Details

#executeObject



12
13
14
15
16
# File 'lib/crypto_toolchain/tools/aes_ctr_recoverer.rb', line 12

def execute
  (0...(ciphertext.length)).each_with_object("") do |i, memo|
    memo << get_character(i)
  end
end

#get_character(i) ⇒ Object

Raises:

  • (RuntimeError)


18
19
20
21
22
23
24
25
26
# File 'lib/crypto_toolchain/tools/aes_ctr_recoverer.rb', line 18

def get_character(i)
  (0..255).each do |byte|
    chr = byte.chr
    if editor.edit(offset: i, with: chr) == ciphertext
      return chr
    end
  end
  raise RuntimeError, "Could not recover character"
end