summaryrefslogtreecommitdiffstats
path: root/enc/xor.go
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-08-29 13:30:47 -0400
committerrsiddharth <s@ricketyspace.net>2020-08-29 13:30:47 -0400
commit9db1426878ff5b81f66d6d73bf69555eb8e5b5d2 (patch)
treed57e6cff053740fe21b74bfdc36d5bcea4908144 /enc/xor.go
parentbd75e7268a8f5532f8348fcd82552ca8d38e7679 (diff)
challenge: do challenge 2
* challenge/c02.go: Challenge 2 snafu. * cryptopals.go: Add challenge 2. * enc/hex.go (DecToHexChar): New function. * enc/xor.go (FixedXOR): New function.
Diffstat (limited to 'enc/xor.go')
-rw-r--r--enc/xor.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/enc/xor.go b/enc/xor.go
new file mode 100644
index 0000000..423c0a2
--- /dev/null
+++ b/enc/xor.go
@@ -0,0 +1,19 @@
+package enc
+
+func FixedXOR(a, b string) string {
+ cs := ""
+ if len(a) != len(b) {
+ return cs
+ }
+
+ ab := []byte(a)
+ bb := []byte(b)
+ for i := 0; i < len(ab); i++ {
+ p := HexCharToDec(ab[i])
+ q := HexCharToDec(bb[i])
+ r := DecToHexChar(p ^ q)
+
+ cs += string(r)
+ }
+ return cs
+}