From 52f09ad3da9d8d11abef07c85179ac52b5bed842 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 6 Sep 2020 22:04:33 -0400 Subject: lib: add FixedXORBytes * lib/xor.go (FixedXORBytes): New function. --- lib/xor.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/xor.go') diff --git a/lib/xor.go b/lib/xor.go index 0d1f3d7..7b57d82 100644 --- a/lib/xor.go +++ b/lib/xor.go @@ -22,6 +22,18 @@ func FixedXOR(a, b string) string { return cs } +func FixedXORBytes(as, bs []byte) []byte { + if len(as) != len(bs) { + return make([]byte, 0) + } + + cs := make([]byte, len(as)) + for i := 0; i < len(as); i++ { + cs[i] = as[i] ^ bs[i] + } + return cs +} + // Both 'data' and 'key' need to be plain ascii string. func RepeatingXOR(data, key string) string { xs := "" -- cgit v1.2.3