From 37004a756479c0f8b27a232ca7cd7f96e5d8d084 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 6 Sep 2020 22:17:02 -0400 Subject: lib: update KeySizeWithMinDistance * lib/hamming.go (KeySizeWithMinDistance): Add argument 'bs'. Use first K bytes and next K bytes of 'bs' for 'p' and 'q'. --- lib/hamming.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/hamming.go') 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) -- cgit v1.2.3