diff options
author | iximeow <me@iximeow.net> | 2014-11-28 03:15:21 -0800 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2014-11-28 03:15:21 -0800 |
commit | 409e8109d8076058e4f154272270a79b6844da18 (patch) | |
tree | b98297162d542506bd4eb911532b349608dfc2d7 /src/solvers | |
parent | 0af5a2e4ade0b032e1ec6d25c51de2ff95dd2799 (diff) |
Refactor CBC utils
Diffstat (limited to 'src/solvers')
-rw-r--r-- | src/solvers/Challenge10.scala | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/src/solvers/Challenge10.scala b/src/solvers/Challenge10.scala index a130106..7880327 100644 --- a/src/solvers/Challenge10.scala +++ b/src/solvers/Challenge10.scala @@ -6,9 +6,8 @@ import ixee.cryptopals.utils.StreamUtils._ import ixee.cryptopals.utils.ConversionUtils._ import ixee.cryptopals.utils.FunctionUtils._ import ixee.cryptopals.utils._ +import ixee.cryptopals.utils.crypto._ import io.github.marklister.base64.Base64._ -import javax.crypto.Cipher -import javax.crypto.spec.SecretKeySpec object Challenge10 { val path = "./data/10.txt" @@ -22,30 +21,23 @@ object Challenge10 { .toByteArray def run = { - val encInstance = CryptoUtils.cbcEncryptInstance( - "AES", - "YELLOW SUBMARINE".asBytes.toArray, - Stream.continually(0.toByte).take(16) - ) - - val decInstance = CryptoUtils.cbcDecryptInstance( - "AES", - "YELLOW SUBMARINE".asBytes.toArray, - Stream.continually(0.toByte).take(16) - ) - - val s = "foo bar frobnicator the quick brown fox jumps over the lazy dog".asBytes - - val enc = encInstance.enc(s) ++ encInstance.end() - val dec = decInstance.dec(enc) - println(dec.startsWith(enc)) - - val decInstance2 = CryptoUtils.cbcDecryptInstance( - "AES", - "YELLOW SUBMARINE".asBytes.toArray, - Stream.continually(0.toByte).take(16) - ) - - decInstance2.dec(ciphertext) + def cbcBuilder = SchemeBuilder("AES", "YELLOW SUBMARINE".asBytes) + .cbc(Stream.continually(0.toByte).take(16)) + + val encInstance = cbcBuilder.encrypt + val decInstance = cbcBuilder.decrypt + + val s = "fooo bar frobnicator the quick brown fox jumps over the lazy dog".asBytes + + println(s) + val enc = encInstance.end(s) + val dec = decInstance.end(enc) + println(enc) + println(dec) + println(dec.startsWith(s)) + + val decInstance2 = cbcBuilder.decrypt + + decInstance2.end(ciphertext) } } |