diff options
author | rsiddharth <s@ricketyspace.net> | 2020-08-29 20:00:53 -0400 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-08-29 20:00:53 -0400 |
commit | 3b0fb163cbac08a36b01f186b72e2a9cee4b7a2d (patch) | |
tree | 5c33a9744c675edb87e29e771b90ed2dfc9a2779 /lib/hex.go | |
parent | ed26b39e82cee901c785c13e3d1b669fbb502e14 (diff) |
challenge: do challenge 3
* challenge/c03.go: Implement challenge 3
* cryptopals.go (main): Add handling to run challenge 3
* lib/brute.go (XORCrackSingleKey): New function.
* lib/hex.go (HexStrToAsciiStr, ByteToHexStr): New functions.
* lib/str.go (FillStr): New function.
Diffstat (limited to 'lib/hex.go')
-rw-r--r-- | lib/hex.go | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -24,3 +24,32 @@ func DecToHexChar(i uint16) byte { } return 0 } + +// 'h' must be hex encoded string. +func HexStrToAsciiStr(h string) string { + a := "" + lh := len(h) + + if lh < 1 { + return a + } + if lh == 1 { + return string(HexCharToDec(h[0])) + } + + for i := 0; i < lh; i += 2 { + b := HexCharToDec(h[i])<<4 | HexCharToDec(h[i+1]) + a += string(b) + } + return a +} + +func ByteToHexStr(b byte) string { + p := DecToHexChar(uint16(b >> 4)) + q := DecToHexChar(uint16(b & 0xf)) + + s := string(p) + s += string(q) + + return s +} |