summaryrefslogtreecommitdiff
path: root/test/Set1Spec.scala
blob: a7a8ef6990c17167e355d3b5a135316df87d1144 (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
package ixee.cryptopals.test

import com.ixee.IxeeSpec

class Set1Spec extends IxeeSpec {

  import ixee.cryptopals.utils.ConversionUtils._
  import ixee.cryptopals.utils.ByteUtils._
  import ixee.cryptopals.solvers._

  "Set1" - {

    "Challenge 1: converts from a hex string to base64" in {

      hexStr2Base64String(
        "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"
      ) mustBe(
        "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"
      )
    }

    "Challenge 2: xor's two equal-length buffers" in {

      val a = hexStr2Bytes(
        "1c0111001f010100061a024b53535009181c"
      )
      val b = hexStr2Bytes(
        "686974207468652062756c6c277320657965"
      )

      (a xor b).hex mustBe
        "746865206b696420646f6e277420706c6179"
    }

    "Challenge 3: single-byte xor cipher" in {
      XorDecrypt.findBestSingleByteKey(
        hexStr2Bytes(
          "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"
        )
      ) mustBe 88.toByte
    }
  }

}