diff options
author | iximeow <me@iximeow.net> | 2014-11-28 04:22:20 -0800 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2014-11-28 04:22:20 -0800 |
commit | 47888049de29336c3f753d0372b37923d8c71121 (patch) | |
tree | 1cd7d3ee2e2d6f0ed3b1357e285f87120bc50dd8 /src/utils/CryptoUtils.scala | |
parent | 6268e2c446d6d54b43668d859184d6f3a779fa3a (diff) |
Challenge 11
Diffstat (limited to 'src/utils/CryptoUtils.scala')
-rw-r--r-- | src/utils/CryptoUtils.scala | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils/CryptoUtils.scala b/src/utils/CryptoUtils.scala index 54e5034..7a31002 100644 --- a/src/utils/CryptoUtils.scala +++ b/src/utils/CryptoUtils.scala @@ -1,6 +1,8 @@ package ixee.cryptopals.utils import ixee.cryptopals.utils.crypto._ +import ixee.cryptopals.utils.StreamUtils._ +import ixee.cryptopals.utils.FunctionUtils._ import javax.crypto.Cipher import javax.crypto.spec.SecretKeySpec @@ -19,4 +21,24 @@ object CryptoUtils { def cbcDecrypt(builder: CbcBuilder)(data: Seq[Byte]) = stripPkcs7Pad(builder.decrypt.end(data)) + + def ecbEncrypt(builder: EcbBuilder)(data: Seq[Byte]) = + builder.encrypt.end(data) + + def ecbDecrypt(builder: EcbBuilder)(data: Seq[Byte]) = + stripPkcs7Pad(builder.decrypt.end(data)) + + def detectMode(xs: Seq[Byte]): String = { + def dupBlocks(xs: Seq[Seq[Byte]]) = + pairsOf(xs).map(tup(_ == _)).count(_ == true) + + def countDupBlocks(xs: Seq[Byte]): Int = + dupBlocks(xs.grouped(16).toSeq.init.toStream) + + //.... well very probably. + if (countDupBlocks(xs) > 0) "ECB" + else "CBC" + + } + } |