summaryrefslogtreecommitdiffstats
path: root/lib/hamming.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-09-06 22:17:02 -0400
committerrsiddharth <s@ricketyspace.net>2020-09-06 22:17:02 -0400
commit37004a756479c0f8b27a232ca7cd7f96e5d8d084 (patch)
treeb6d19f20690468f9aad3a75873f2f063b978b615 /lib/hamming.go
parentcdba778e7986fd4543ea2deaee4d6bdafb858f68 (diff)
lib: update KeySizeWithMinDistance
* lib/hamming.go (KeySizeWithMinDistance): Add argument 'bs'. Use first K bytes and next K bytes of 'bs' for 'p' and 'q'.
Diffstat (limited to 'lib/hamming.go')
-rw-r--r--lib/hamming.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/hamming.go b/lib/hamming.go
index d9801a4..e53916c 100644
--- a/lib/hamming.go
+++ b/lib/hamming.go
@@ -35,12 +35,12 @@ func setBits(b byte) int {
// Returns key size with minimum normalized hamming distance
// 'keyMin' is the minimum key size
// 'keyMax' is the maximum key size
-func KeySizeWithMinDistance(keyMin, keyMax int) int {
+func KeySizeWithMinDistance(keyMin, keyMax int, bs []byte) int {
var mk int = 0 // Key size with min distance.
var md float64 = 100.0 // Distance for key size 'mk'.
for k := keyMin; k <= keyMax; k++ {
- p := genKey(k)
- q := genKey(k)
+ p := bs[0 : k*8] // K bytes.
+ q := bs[k*8 : k*8*2] // Next K bytes.
// Compute distance.
d := HammingDistance(p, q)