summaryrefslogtreecommitdiffstats
path: root/enc/hex.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/hex.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/hex.go')
-rw-r--r--enc/hex.go10
1 files changed, 10 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
+}