class CryptoToolchain::BlackBoxes::CtrBitflipTarget

Attributes

key[R]
nonce[R]

Public Class Methods

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

Public Instance Methods

encrypt(input) click to toggle source
# File lib/crypto_toolchain/black_boxes/ctr_bitflip_target.rb, line 10
def encrypt(input)
  str = prefix + input.gsub(/;|=/, "") + suffix
  str.encrypt_ctr(key: key,  nonce: nonce)
end
is_admin?(crypted) click to toggle source
# File lib/crypto_toolchain/black_boxes/ctr_bitflip_target.rb, line 15
def is_admin?(crypted)
  crypted.decrypt_ctr(key: key, nonce: nonce).include?(";admin=true;")
end

Private Instance Methods

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