Matasano Crypto Challenges - Set 1 - Challenge 2 - Solved in Go

written in cryptopals, go, matasano, programming

This is the solution I came up with in Go for Set 1 / Challenge 2 of the matasano crypto challenges.

Code after the break…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import hex "encoding/hex"
import "fmt"

func main() {

    source1 := "1c0111001f010100061a024b53535009181c"
    source2 := "686974207468652062756c6c277320657965"

    source1Hex, _ := hex.DecodeString(source1)
    source2Hex, _ := hex.DecodeString(source2)

    finalHex := make([]byte, 0)

    for i, b := range source1Hex {
        finalHex = append(finalHex, b^source2Hex[i])
    }

    finalHexString := hex.EncodeToString(finalHex)

    fmt.Println(finalHexString)
}

Running this will output the expected result, like so:

1
2
Pu:~ nate$ go run Set1Challenge2.go
746865206b696420646f6e277420706c6179

Comments