mirror of
https://github.com/gregtwallace/apc-p15-tool.git
synced 2025-01-22 08:14:08 +00:00
add bitwise funcs for CEK encrypt/decrypt
This commit is contained in:
parent
ff1953e7c7
commit
2dd129c60a
1 changed files with 32 additions and 0 deletions
32
bitwise.go
Normal file
32
bitwise.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
// bitwiseComplimentOf returns the bitwise compliment of data
|
||||||
|
func bitwiseComplimentOf(data []byte) []byte {
|
||||||
|
compliment := []byte{}
|
||||||
|
|
||||||
|
for i := range data {
|
||||||
|
compliment = append(compliment, ^data[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return compliment
|
||||||
|
}
|
||||||
|
|
||||||
|
// isBitwiseCompliment returns true if data1 and data2 are bitwise compliments,
|
||||||
|
// otherwise it returns false
|
||||||
|
func isBitwiseCompliment(data1, data2 []byte) bool {
|
||||||
|
// 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
|
||||||
|
}
|
Loading…
Reference in a new issue