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) } } } } }