package xor import "math" /* (1) bitwise XOR between bytes * * @_left Left operand * @_right Right operand * * @return out Bitwise XOR result between _left and _right * ---------------------------------------------------------*/ func Byte(_left byte, _right byte) byte { return _left ^ _right } /* (2) bitwise XOR between Byte arrays * * @_left Left operand * @_right Right operand * * @return out Bitwise XOR result between _left and _right * * @@ NOTE @@ * If an argument is smaller, it will be right-padded with null bytes (0x00) * ---------------------------------------------------------*/ func ByteArray(_left []byte, _right []byte) []byte { /* (1) Process ---------------------------------------------------------*/ /* (1) Extract lengths */ ll := len(_left) lr := len(_right) /* (2) Get max length */ l := int(math.Max(float64(ll), float64(lr))) /* (3) Initialise 'out' */ out := make([]byte, l, l) /* (2) Process bitwise XOR */ for i := 0; i < l; i++ { // 1. Out of range for _left if i >= ll { out[i] = _right[i] } else if i >= lr { out[i] = _left[i] } else { out[i] = Byte(_left[i], _right[i]) } } return out }