class CryptoToolchain::Tools::AesCtrRecoverer

Attributes

ciphertext[R]
editor[R]

Public Class Methods

new(editor) click to toggle source
# File lib/crypto_toolchain/tools/aes_ctr_recoverer.rb, line 7
def initialize(editor)
  @editor = editor
  @ciphertext = editor.ciphertext
end

Public Instance Methods

execute() click to toggle source
# 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) click to toggle source
# 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