package ixee.cryptopals.solvers import scala.io.Source import ixee.cryptopals.utils.ByteUtils._ import ixee.cryptopals.utils.CryptoUtils._ import ixee.cryptopals.utils.StreamUtils._ import ixee.cryptopals.utils.ConversionUtils._ import ixee.cryptopals.utils.FunctionUtils._ import ixee.cryptopals.utils._ import ixee.cryptopals.utils.crypto._ import io.github.marklister.base64.Base64._ object Challenge12 { lazy val mysteryText = """|Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkg |aGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq |dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUg |YnkK""".stripMargin.replace("\n", "").toByteArray val expectation = """|Rollin' in my 5.0 |With my rag-top down so my hair can blow |The girlies on standby waving just to say hi |Did you stop? No, I just drove by |""".stripMargin val key = """|Copy your oracle function to a new function that | encrypts buffers under ECB mode using a consistent | but unknown key (for instance, assign a single | random key, once, to a global variable).""".stripMargin .replace("\n", "") .asBytes .grouped(16) .toSeq .init .reduce(_ xor _) def encryptFn(input: Seq[Byte]): Seq[Byte] = SchemeBuilder("AES", key).ecb.encrypt.end(input ++ mysteryText) def run = { CryptoUtils.extractUnknownViaEcbOracle(encryptFn _) } }