summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-09-06 22:04:33 -0400
committerrsiddharth <s@ricketyspace.net>2020-09-06 22:04:33 -0400
commit52f09ad3da9d8d11abef07c85179ac52b5bed842 (patch)
tree277dbff233a2c3aef26f182b65d95f676522cfc5
parentc16fc07b988aac8217fa16c912e460e994ae2363 (diff)
lib: add FixedXORBytes
* lib/xor.go (FixedXORBytes): New function.
-rw-r--r--lib/xor.go12
1 files changed, 12 insertions, 0 deletions
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 := ""