summaryrefslogtreecommitdiffstats
path: root/lib/hamming.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-09-05 10:41:28 -0400
committerrsiddharth <s@ricketyspace.net>2020-09-05 10:41:28 -0400
commit4af1ff746740ef70e03d6edae272d1fcdffba35a (patch)
tree4fc2672dbdbc897ac781a21410e4610163be30ca /lib/hamming.go
parentb28784b5890d5fdc7cd9d4b9bd05d497e19ca6cb (diff)
lib: add KeySizeWithMinDistanceIter
* lib/hamming.go (KeySizeWithMinDistanceIter): New function.
Diffstat (limited to 'lib/hamming.go')
-rw-r--r--lib/hamming.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/hamming.go b/lib/hamming.go
index 05a7546..3ed4611 100644
--- a/lib/hamming.go
+++ b/lib/hamming.go
@@ -32,6 +32,20 @@ func setBits(b byte) int {
return int(c)
}
+// Returns average key size with minimum normalized hamming distance.
+// 'keyMin' is the minimum key size
+// 'keyMax' is the maximum key size
+// 'iterate' is the number of times to iterate.
+func KeySizeWithMinDistanceIter(keyMin, keyMax, iterate int) int {
+ sum := 0
+ avg := 0.0
+ for i := 0; i < iterate; i++ {
+ sum += KeySizeWithMinDistance(keyMin, keyMax)
+ }
+ avg = float64(sum) / float64(iterate)
+
+ return int(avg)
+}
// Returns key size with minimum normalized hamming distance
// 'keyMin' is the minimum key size