diff options
author | iximeow <me@iximeow.net> | 2014-11-28 03:40:17 -0800 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2014-11-28 03:40:17 -0800 |
commit | 6268e2c446d6d54b43668d859184d6f3a779fa3a (patch) | |
tree | c9333b6130f0032b33bdd54194e3e41be62cf6b4 /test | |
parent | 409e8109d8076058e4f154272270a79b6844da18 (diff) |
Fix challenge 10 specs
Diffstat (limited to 'test')
-rw-r--r-- | test/Set2Spec.scala | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/test/Set2Spec.scala b/test/Set2Spec.scala index 7884b4e..d230a18 100644 --- a/test/Set2Spec.scala +++ b/test/Set2Spec.scala @@ -7,7 +7,9 @@ class Set2Spec extends IxeeSpec { import ixee.cryptopals.utils.ConversionUtils._ import ixee.cryptopals.utils.ByteUtils._ import ixee.cryptopals.utils.StreamUtils._ + import ixee.cryptopals.utils.CryptoUtils._ import ixee.cryptopals.utils._ + import ixee.cryptopals.utils.crypto.SchemeBuilder import ixee.cryptopals.solvers._ "Set2" - { @@ -23,7 +25,7 @@ class Set2Spec extends IxeeSpec { def challenge9spec(expected: Byte) = { val truncated = text.dropRight(expected) val padString = - CryptoUtils.pkcs7pad(truncated.toByteArray, 256).takeRight(expected) + pkcs7pad(truncated.asBytes, 256).takeRight(expected) val expectedPad = s"${expected.toChar}" * expected @@ -43,7 +45,32 @@ class Set2Spec extends IxeeSpec { "Challenge 10: Implement CBC mode" - { - + "encryption then decryption produces the original data" in { + + val text = """|what a nice string the quick brown fox + | and the lazy dog went for a jog in the park. + |In touch with the ground + |I'm on the hunt I'm after you + |Smell like I sound, I'm lost in a crowd + |And I'm hungry like the wolf + |Straddle the line in discord and rhyme + |I'm on the hunt I'm after you + |Mouth is alive with juices like wine + |And I'm hungry like the wolf + | the wolf ate both of them.""".stripMargin + + val builder = SchemeBuilder("AES", "foobar, a nice s".asBytes) + .cbc(Stream.from(10).take(16).map(_.toByte)) + + cbcDecrypt(builder)(cbcEncrypt(builder)(text.asBytes)) mustBe text.asBytes + + } + + "decrypts the example data" in { + + Challenge10.run mustBe Challenge6.expectation + + } } } |