Exemple #1
0
func main() {
	fmt.Println("My Cryptopals Challenge Results:")

	// Set 1 - Challenge 1
	fmt.Println("Set 1 - Challenge 1")
	expected := "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"
	input := "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"
	hex := util.Atoh(input)
	encoded := b64.Encode(hex)
	actual := util.B64toa(encoded)
	fmt.Printf("\tInput:\t\t%s\n\tResult:\t\t%s\n\tExpected:\t%s\n\tSuccess? %t\n", input, actual, expected, actual == expected)

	// Set 1 - Challenge 2
	fmt.Println("Set 1 - Challenge 2")
	input = "1c0111001f010100061a024b53535009181c"
	xorWith := "686974207468652062756c6c277320657965"
	expected = "746865206b696420646f6e277420706c6179"
	result := xor.FixedXor(util.Atoh(input), util.Atoh(xorWith))
	actual = util.Htoa(result)
	fmt.Printf("\tInput:\t\t%s\n\tResult:\t\t%s\n\tExpected:\t%s\n\tSuccess? %t\n", input, actual, expected, actual == expected)

	// Set 1 - Challenge 3
	fmt.Println("Set 1 - Challenge 3")
	input = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"
	results := xor.CipherDecryption(util.Atoh(input), 0.25)
	for _, r := range results {
		fmt.Printf("\t%s\n", r)
	}
}
func TestChallenge2(t *testing.T) {
	input := "1c0111001f010100061a024b53535009181c"
	xorWith := "686974207468652062756c6c277320657965"
	expected := "746865206b696420646f6e277420706c6179"

	result := xor.FixedXor(util.Atoh(input), util.Atoh(xorWith))
	actual := util.Htoa(result)

	if actual != expected {
		fmt.Println("Expected:", expected, "Actual:", actual)
		t.Fail()
	}
}