Skip to content

Instantly share code, notes, and snippets.

@prakhar1989
Created August 12, 2014 16:01
Show Gist options
  • Save prakhar1989/56f45bc1ee5800905e3c to your computer and use it in GitHub Desktop.
Save prakhar1989/56f45bc1ee5800905e3c to your computer and use it in GitHub Desktop.
Matasano Crypto
package main
import (
"fmt"
"encoding/hex"
"encoding/base64"
)
func main() {
s := "1c0111001f010100061a024b53535009181c"
t := "686974207468652062756c6c277320657965"
fmt.Println(fixedXOR(s, u))
}
// set 1 - Challenge 1
// Usage: Returns a base64 encoded version of a hex encoded string
func hexToBase64(s string) string {
h, err := hex.DecodeString(s) //[]byte
if err != nil {
fmt.Println("Error: ", err)
}
return base64.StdEncoding.EncodeToString(h)
}
// set 1 - Challenge 2
// LESSON: a ^ b = c; c ^ a = b; b ^ c = a
// Usage: Finds the xor between two hex encoded strings
func fixedXOR(s string, t string) string {
a, _ := hex.DecodeString(s)
b, _ := hex.DecodeString(t)
x := make([]byte, len(a))
for i := 0; i < len(a); i++ {
x[i] = a[i] ^ b[i]
}
return hex.EncodeToString(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment