diff options
author | iximeow <me@iximeow.net> | 2014-11-26 18:10:58 -0800 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2014-11-26 18:11:50 -0800 |
commit | 91b4cfc801b7c156c231ca60aba69a8d171e9226 (patch) | |
tree | 189262a5e86aea229374e9786edb08ff90d16d09 /src/solvers/XorDecrypt.scala | |
parent | 31cac438b1571ba6ced29af4997cf9f1f5c3c6b7 (diff) |
Challenge 8, 9
Diffstat (limited to 'src/solvers/XorDecrypt.scala')
-rw-r--r-- | src/solvers/XorDecrypt.scala | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/solvers/XorDecrypt.scala b/src/solvers/XorDecrypt.scala index 83fa923..1a28637 100644 --- a/src/solvers/XorDecrypt.scala +++ b/src/solvers/XorDecrypt.scala @@ -30,7 +30,7 @@ object XorDecrypt { } def normalizedHammingDistanceForKeySize(xs: Seq[Byte], keySize: Int) = { - val grouped = xs.grouped(keySize).toArray.dropRight(1) + val grouped = xs.grouped(keySize).toArray.init // ez hack to drop non-`keySize` subcomponents of xs (grouped.init zip grouped.tail).map(tup(hammingDistance(_, _))).reduce(_ + _) / (grouped.length - 1.0) / keySize } @@ -64,7 +64,7 @@ object XorDecrypt { def findBestMultiByteKeyOfSize(keySize: Int)(ciphertext: Seq[Byte], inspectSet: Seq[Int] = Seq()): Seq[Byte] = { // inspectSet is the set of key bytes for which we want debugging information - ciphertext.grouped(keySize).toSeq.dropRight(1).transpose.zipWithIndex + ciphertext.grouped(keySize).toSeq.init.transpose.zipWithIndex .map { case (byteCiphertext, idx) => { if (inspectSet.contains(idx)) { println("For idx = " + idx) |