-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercise12Tests.scala
44 lines (38 loc) · 1.25 KB
/
Exercise12Tests.scala
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
package Set2
import java.util.Base64
import java.util.Base64.Decoder
import org.junit.Test
import org.scalatest.junit.JUnitSuite
import Set2.Exercise12._
import Util.Util._
import Set1.Exercise8._
import scala.io.Source
class Exercise12Tests extends JUnitSuite {
@Test
def testDetectBlockSize() = {
assert(detectECBBlockSize(encryption_oracle) == 16)
}
@Test
def testAnswerMap() = {
val blocksize = 16
val bytes = ("A"*(blocksize-1)).getBytes
val map = createAnswerMap(encryption_oracle, blocksize, 0, bytes)
val ciphertext = encryption_oracle(bytes).slice(0,blocksize)
val attempt = map(ciphertext)
val solution = bytes :+ 'R'.toByte
assert(toHexString(solution) === toHexString(attempt))
}
@Test
def testRecoverBlock() = {
val blocksize = 16
val b: Seq[Byte] = recoverBlock(encryption_oracle, blocksize, Seq[Byte](), 0)
assert(toASCIIString(b.toArray) == "Rollin' in my 5.")
}
@Test
def testMatasano() = {
val blocksize = 16
val answerBytes = Base64.getDecoder.decode(Source.fromURL(getClass.getResource("/Exercise12TestData.txt")).getLines().mkString.getBytes)
val b: Seq[Byte] = recoverSecret(encryption_oracle, blocksize)
assert(toHexString(answerBytes) == toHexString(b.toArray))
}
}