diff options
Diffstat (limited to 'src/solvers')
-rw-r--r-- | src/solvers/Challenge12.scala | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/solvers/Challenge12.scala b/src/solvers/Challenge12.scala new file mode 100644 index 0000000..b37b5e3 --- /dev/null +++ b/src/solvers/Challenge12.scala @@ -0,0 +1,39 @@ +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 { + val path = "./data/10.txt" + + lazy val mysteryText = + """|Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkg + |aGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBq + |dXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUg + |YnkK""".stripMargin.replace("\n", "").toByteArray + + 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 _) + } +} |