summaryrefslogtreecommitdiff
path: root/src/solvers/Challenge7.scala
blob: ee1745a2f3c9b7dd4f8fd4a1f54344404a215221 (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
package ixee.cryptopals.solvers

import scala.io.Source
import ixee.cryptopals.utils.ByteUtils._
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 Challenge7 {
  val path = "./data/7.txt"

  lazy val ciphertext =
    Source
      .fromFile(path)
      .getLines()
      .toSeq
      .flatten
      .mkString
      .toByteArray

  val key = new SecretKeySpec(
    "YELLOW SUBMARINE".asBytes.toArray,
    "AES"
  )

  def run = {
    val cipher = Cipher.getInstance(
      "AES/ECB/PKCS5Padding"
    )
    cipher.init(Cipher.DECRYPT_MODE, key)
    new String(cipher.doFinal(ciphertext))
  }
}