2024-01-26 01:16:37 +00:00
|
|
|
package tools
|
2024-01-21 20:09:31 +00:00
|
|
|
|
2024-01-26 01:16:37 +00:00
|
|
|
// BitwiseComplimentOf returns the bitwise compliment of data
|
|
|
|
func BitwiseComplimentOf(data []byte) []byte {
|
2024-01-21 20:09:31 +00:00
|
|
|
compliment := []byte{}
|
|
|
|
|
|
|
|
for i := range data {
|
|
|
|
compliment = append(compliment, ^data[i])
|
|
|
|
}
|
|
|
|
|
|
|
|
return compliment
|
|
|
|
}
|
|
|
|
|
2024-01-26 01:16:37 +00:00
|
|
|
// IsBitwiseCompliment returns true if data1 and data2 are bitwise compliments,
|
2024-01-21 20:09:31 +00:00
|
|
|
// otherwise it returns false
|
2024-01-26 01:16:37 +00:00
|
|
|
func IsBitwiseCompliment(data1, data2 []byte) bool {
|
2024-01-21 20:09:31 +00:00
|
|
|
// if not same length, definitely not compliments
|
|
|
|
if len(data1) != len(data2) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// check each byte
|
|
|
|
for i := range data1 {
|
|
|
|
// if any byte is NOT the bitwise compliment of the matching byte in other data
|
|
|
|
// set, then the full set is not bitwise compliment and false
|
|
|
|
if data1[i] != ^data2[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|