Created
May 17, 2017 19:11
-
-
Save aerth/d8278fe3cfaad9a8580a92bdf7b5cc0c to your computer and use it in GitHub Desktop.
cryptopal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cryptopal | |
import ( | |
"encoding/base64" | |
"encoding/hex" | |
"testing" | |
) | |
var input = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d" | |
var gold = "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t" | |
var b64 = base64.RawURLEncoding | |
// challenge 1 | |
func TestHex2Base64(t *testing.T) { | |
t.Log("hex:", input) | |
var decoded = make([]byte, hex.DecodedLen(len([]byte(input)))) | |
_, err := hex.Decode(decoded, []byte(input)) | |
if err != nil { | |
t.Log(err) | |
t.FailNow() | |
} | |
t.Log("plain:", string(decoded)) | |
bb := make([]byte, b64.EncodedLen(len(decoded))) | |
b64.Encode(bb, decoded) | |
if gold != string(bb) { | |
t.Log("wanted:", gold) | |
t.Log("got:", string(bb)) | |
t.FailNow() | |
} | |
t.Log("base64:", string(bb)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment