summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2014-11-26 18:10:58 -0800
committeriximeow <me@iximeow.net>2014-11-26 18:11:50 -0800
commit91b4cfc801b7c156c231ca60aba69a8d171e9226 (patch)
tree189262a5e86aea229374e9786edb08ff90d16d09 /test
parent31cac438b1571ba6ced29af4997cf9f1f5c3c6b7 (diff)
Challenge 8, 9
Diffstat (limited to 'test')
-rw-r--r--test/Set1Spec.scala6
-rw-r--r--test/Set2Spec.scala46
2 files changed, 52 insertions, 0 deletions
diff --git a/test/Set1Spec.scala b/test/Set1Spec.scala
index b017803..67eadfc 100644
--- a/test/Set1Spec.scala
+++ b/test/Set1Spec.scala
@@ -131,6 +131,12 @@ class Set1Spec extends IxeeSpec {
Challenge7.run mustBe Challenge6.expectation
}
+
+ "Challenge 8: Detect ECB" in {
+
+ Challenge8.run mustBe 133
+
+ }
}
}
diff --git a/test/Set2Spec.scala b/test/Set2Spec.scala
new file mode 100644
index 0000000..efcb5b0
--- /dev/null
+++ b/test/Set2Spec.scala
@@ -0,0 +1,46 @@
+package ixee.cryptopals.test
+
+import com.ixee.IxeeSpec
+
+class Set2Spec extends IxeeSpec {
+
+ import ixee.cryptopals.utils.ConversionUtils._
+ import ixee.cryptopals.utils.ByteUtils._
+ import ixee.cryptopals.utils.StreamUtils._
+ import ixee.cryptopals.utils._
+ import ixee.cryptopals.solvers._
+
+ "Set2" - {
+
+ "Challenge 9: Implement PKCS#7 padding" - {
+
+ "when n bytes are missing" - {
+
+ "fill with n bytes of value n" in {
+
+ val text = "what a nice stri" * 16 * 2
+
+ def challenge9spec(expected: Byte) = {
+ val truncated = text.dropRight(expected)
+ val padString =
+ CryptoUtils.pkcs7pad(truncated, 256).takeRight(expected)
+
+ val expectedPad =
+ s"${expected.toChar}" * expected
+
+ padString mustBe expectedPad
+ }
+
+ for {
+ x <- 1 to 255
+ } yield challenge9spec(x.toByte)
+
+ }
+
+ }
+
+ }
+
+ }
+
+}