summaryrefslogtreecommitdiffstats
path: root/enc
diff options
context:
space:
mode:
Diffstat (limited to 'enc')
-rw-r--r--enc/hex.go10
-rw-r--r--enc/xor.go19
2 files changed, 29 insertions, 0 deletions
diff --git a/enc/hex.go b/enc/hex.go
index 0d19538..a1b9b46 100644
--- a/enc/hex.go
+++ b/enc/hex.go
@@ -14,3 +14,13 @@ func HexCharToDec(c byte) uint16 {
}
return 0
}
+
+func DecToHexChar(i uint16) byte {
+ switch {
+ case 0 <= i && i <= 9:
+ return byte(48 + i)
+ case 10 <= i && i <= 15:
+ return byte(97 + (i - 10))
+ }
+ return 0
+}
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
+}