Class: CryptoToolchain::Tools::AesCtrRecoverer
- Defined in:
- lib/crypto_toolchain/tools/aes_ctr_recoverer.rb
Instance Attribute Summary collapse
-
#ciphertext ⇒ Object
readonly
Returns the value of attribute ciphertext.
-
#editor ⇒ Object
readonly
Returns the value of attribute editor.
Instance Method Summary collapse
- #execute ⇒ Object
- #get_character(i) ⇒ Object
-
#initialize(editor) ⇒ AesCtrRecoverer
constructor
A new instance of AesCtrRecoverer.
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
#ciphertext ⇒ Object (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 |
#editor ⇒ Object (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
#execute ⇒ Object
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
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 |