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) int

Parameters & Attributes

NameTypeDescription
dst[]byteDestination of at least min(len(x), len(y)) bytes.
x[]byteFirst source.
y[]byteSecond 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)}
Go Reference