class CryptoToolchain::BlackBoxes::CbcBitflipTarget

Attributes

iv[R]
key[R]

Public Class Methods

new(key: Random.new.bytes(16), iv: Random.new.bytes(16)) click to toggle source
# File lib/crypto_toolchain/black_boxes/cbc_bitflip_target.rb, line 5
def initialize(key: Random.new.bytes(16), iv: Random.new.bytes(16))
  @key = key
  @iv = iv
end

Public Instance Methods

encrypt(input) click to toggle source
# File lib/crypto_toolchain/black_boxes/cbc_bitflip_target.rb, line 10
def encrypt(input)
  str = prefix + input.gsub(/;|=/, "") + suffix
  str.encrypt_cbc(key: key, blocksize: 16, iv: iv)
end
is_admin?(crypted) click to toggle source
# File lib/crypto_toolchain/black_boxes/cbc_bitflip_target.rb, line 15
def is_admin?(crypted)
  dec = crypted.decrypt_cbc(key: key, blocksize: 16, iv: iv)
  dec.include?(";admin=true;")
end

Private Instance Methods

prefix() click to toggle source
# File lib/crypto_toolchain/black_boxes/cbc_bitflip_target.rb, line 24
def prefix
  "comment1=cooking%20MCs;userdata="
end
suffix() click to toggle source
# File lib/crypto_toolchain/black_boxes/cbc_bitflip_target.rb, line 28
def suffix
  ";comment2=%20like%20a%20pound%20of%20bacon"
end