diff options
author | iximeow <me@iximeow.net> | 2014-11-29 14:11:00 -0800 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2014-11-29 14:11:00 -0800 |
commit | 01515fe2c82fb0b05a17bd792f4e45b88f31f235 (patch) | |
tree | 65faeb98df0969e3443fee71e8e2f1e61f0466fe /src/solvers | |
parent | 47888049de29336c3f753d0372b37923d8c71121 (diff) |
Trying to work through 12...
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 _) + } +} |