Standard library / crypto/subtle
crypto/subtle.XORBytes()
XOR corresponding bytes into dst up to the shorter source length. Destination must be large enough or the function panics before writing; use disjoint or exactly overlapping buffers, not partial overlaps. XOR alone is not encryption. Expected stdout: '2 ff00\n'.
Formal Syntax & Structure
go syntaxgo
func XORBytes(dst, x, y []byte) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| dst | []byte | Destination of at least min(len(x), len(y)) bytes. |
| x | []byte | First source. |
| y | []byte | Second source. |
Return Value
int
Number of bytes written.
Working Example
Example Snippetgo
package main
import ( "crypto/subtle" "fmt")
func main() { dst := make([]byte, 2) n := subtle.XORBytes(dst, []byte{0x0f, 0x55}, []byte{0xf0, 0x55, 0}) fmt.Printf("%d %x\n", n, dst)}