blob: a130106ff3667f02e8a50a4af111a9f9d4fe79a0 (
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
40
41
42
43
44
45
46
47
48
49
50
51
|
package ixee.cryptopals.solvers
import scala.io.Source
import ixee.cryptopals.utils.ByteUtils._
import ixee.cryptopals.utils.StreamUtils._
import ixee.cryptopals.utils.ConversionUtils._
import ixee.cryptopals.utils.FunctionUtils._
import ixee.cryptopals.utils._
import io.github.marklister.base64.Base64._
import javax.crypto.Cipher
import javax.crypto.spec.SecretKeySpec
object Challenge10 {
val path = "./data/10.txt"
lazy val ciphertext =
Source
.fromFile(path)
.getLines()
.toSeq
.mkString
.toByteArray
def run = {
val encInstance = CryptoUtils.cbcEncryptInstance(
"AES",
"YELLOW SUBMARINE".asBytes.toArray,
Stream.continually(0.toByte).take(16)
)
val decInstance = CryptoUtils.cbcDecryptInstance(
"AES",
"YELLOW SUBMARINE".asBytes.toArray,
Stream.continually(0.toByte).take(16)
)
val s = "foo bar frobnicator the quick brown fox jumps over the lazy dog".asBytes
val enc = encInstance.enc(s) ++ encInstance.end()
val dec = decInstance.dec(enc)
println(dec.startsWith(enc))
val decInstance2 = CryptoUtils.cbcDecryptInstance(
"AES",
"YELLOW SUBMARINE".asBytes.toArray,
Stream.continually(0.toByte).take(16)
)
decInstance2.dec(ciphertext)
}
}
|