summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-06-19 10:04:46 -0400
committersiddharth <s@ricketyspace.net>2021-06-19 10:04:46 -0400
commite285c8aa4a03b4f96b1ab36a0fd4b1a6e810ec4b (patch)
treec9460c85466548a44855ab0af79de688132518c1 /lib
parent03346243733759bf44ba0bf51a2af4766490c277 (diff)
lib: update RepeatingXOR
- Change input type to []byte. - Change retur type to []byte. - Update RepeatingXOR calls in challenge 5 an 6.
Diffstat (limited to 'lib')
-rw-r--r--lib/xor.go16
1 files changed, 5 insertions, 11 deletions
diff --git a/lib/xor.go b/lib/xor.go
index 7b57d82..31a4b8b 100644
--- a/lib/xor.go
+++ b/lib/xor.go
@@ -35,29 +35,23 @@ func FixedXORBytes(as, bs []byte) []byte {
}
// Both 'data' and 'key' need to be plain ascii string.
-func RepeatingXOR(data, key string) string {
- xs := ""
+func RepeatingXOR(data, key []byte) []byte {
+ xs := make([]byte, 0)
if len(data) < 1 || len(key) < 1 {
return xs
}
- // data in bytes
- db := []byte(data)
-
- // key in bytes
- dk := []byte(key)
-
lk := len(key)
- for i, ki := 0, 0; i < len(db); i++ {
+ for i, ki := 0, 0; i < len(data); i++ {
if ki == lk {
ki = 0
}
// xor a byte
- eb := db[i] ^ dk[ki]
+ eb := data[i] ^ key[ki]
// append to result
- xs += string(eb)
+ xs = append(xs, eb)
ki += 1
}