Class: CryptoToolchain::BlackBoxes::CtrBitflipTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto_toolchain/black_boxes/ctr_bitflip_target.rb

Instance Method Summary collapse

Constructor Details

#initialize(key: Random.new.bytes(16), nonce: rand(0..0x0000FFFF)) ⇒ CtrBitflipTarget

Returns a new instance of CtrBitflipTarget.



5
6
7
8
# 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

Instance Method Details

#encrypt(input) ⇒ Object



10
11
12
13
# 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) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# 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