blob: b37b5e31d7335494c47b72f85f078a36a3c8eca8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 _)
}
}
|