summaryrefslogtreecommitdiff
path: root/src/utils/FrequencyMap.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/FrequencyMap.scala')
-rw-r--r--src/utils/FrequencyMap.scala29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/utils/FrequencyMap.scala b/src/utils/FrequencyMap.scala
index 0bea25c..fffdabe 100644
--- a/src/utils/FrequencyMap.scala
+++ b/src/utils/FrequencyMap.scala
@@ -1,6 +1,6 @@
package ixee.cryptopals.utils
-import ConversionUtils.tup
+import FunctionUtils.tup
class FrequencyMap(mapargs: Map[Char, Double]) {
sealed trait DiffResult
@@ -14,7 +14,7 @@ class FrequencyMap(mapargs: Map[Char, Double]) {
if (c.isLower)
mappings.get(c)
else // TODO remove the bias here
- mappings.get(c.toLower).map(_ * 0.002) // bias HARD against uppercase spam. should make this a per-map setting.
+ mappings.get(c.toLower).map(_ * 0.0002) // bias HARD against uppercase spam. should make this a per-map setting.
def diff(other: FrequencyMap): Double = {
// pseudoscience here
@@ -36,29 +36,30 @@ class FrequencyMap(mapargs: Map[Char, Double]) {
// TODO: don't hardcode these..
def diffAt(c: Char, charFreq: Double) =
- c match {
- case ' ' => 0
- case '{' | '}' | '`' | '|' =>
+ Math.pow(c match {
+ case ' ' =>
+ squared(0.10 - charFreq)
+ case '{' | '}' | '`' | '|' | '^' =>
squared(0.000001 - charFreq) // { } | and ` are very unlikely irl
case '[' | ']' =>
- squared(0.000002 - charFreq) // [ ] are more likely
- case '"' | '\''=>
+ squared(0.0000015 - charFreq) // [ ] are more likely
+ case '"' | '\'' =>
squared(0.00001 - charFreq) // " or ' are 100% unlikely 90% of the time
case '~' | '+' | '=' | '<' | '>' | '/' | '\\' =>
- squared(0.000004 - charFreq) // math is weird kids
+ squared(0.00000175 - charFreq) // math is weird kids
case ';' | ':' | '-' | '*' | '(' | '&' | ')' | '_' =>
- squared(0.000009 - charFreq) // getting into more common punctuation
+ squared(0.000003 - charFreq) // getting into more common punctuation
case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' =>
- squared(0.00001 - charFreq) // numbers are KINDA uncommon
+ squared(0.000002 - charFreq) // numbers are KINDA uncommon
case '$' | '%' | '#' | '@' | '!' =>
- squared(0.00003 - charFreq) // more punctuation...
+ squared(0.00002 - charFreq) // more punctuation...
case '.' | ',' =>
squared(0.00007 - charFreq) // and the last of the punctuations
case '\n' | '\r' =>
- squared(0.0000002 - charFreq) // explicit \r \n is rare in freeform text.
+ squared(0.000001 - charFreq) // explicit \r \n is rare in freeform text.
case _ =>
- this.at(c).map(_ - charFreq).map(squared).getOrElse(0.0)
- }
+ this.at(c).map(_ - charFreq).map(squared).getOrElse(0.4)
+ }, 0.5)
def squared(x: Double) = x * x