-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.go
51 lines (38 loc) · 892 Bytes
/
core.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"encoding/base64"
"encoding/hex"
)
func HexDecodeToBase64(input string) string {
input_byte, _ := hex.DecodeString(input)
result := base64.StdEncoding.EncodeToString(input_byte)
return result
}
func EncodeFixedXor(dst, src, key []byte) {
for i, value := range key {
dst[i] = src[i] ^ value
}
}
func EncodeRepeatingXor(input []byte, key []byte) []byte {
keySize := len(key)
outputByte := make([]byte, len(input))
for i, value := range input {
outputByte[i] = value ^ key[i%keySize]
}
return outputByte
}
func countSetBits(value byte) byte {
result := byte(0)
for value > 0 {
result += value & 1
value >>= 1
}
return result
}
func HammingDistance(firstInput []byte, secondInput []byte) uint {
result := uint(0)
for i := 0; i < len(firstInput); i++ {
result += uint(countSetBits(firstInput[i] ^ secondInput[i]))
}
return result
}