commit 67c029356b1fe359bc143a1ecb61e190d805012a parent 1ac28233b57d87caa99986e645d5a6a31615ee48 Author: Jared Tobin <jared@jtobin.io> Date: Sun, 6 Aug 2023 20:15:30 -0230 Fix padding bug. Diffstat:
M | lib/Cryptopals/Util.hs | | | 10 | ++++++---- |
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/Cryptopals/Util.hs b/lib/Cryptopals/Util.hs @@ -40,10 +40,12 @@ repeatingKeyXor key pla = in BS.pack $ BS.zipWith B.xor ks pla pkcs7 :: Int -> BS.ByteString -> BS.ByteString -pkcs7 tar bs = - let len = BS.length bs - byt = tar - len `mod` tar - in bs <> BS.replicate byt (fromIntegral byt) +pkcs7 tar bs + | BS.length bs `rem` tar == 0 = bs <> BS.replicate 16 16 + | otherwise = + let len = BS.length bs + byt = tar - len `mod` tar + in bs <> BS.replicate byt (fromIntegral byt) -- lazy man's pkcs#7 padding lpkcs7 :: BS.ByteString -> BS.ByteString