Example #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)
	}
}
Example #2
0
func TestAlphabet(t *testing.T) {
	expected := "dGhlcXVpY2ticm93bmZveGp1bXBzb3ZlcnRoZWxhenlkb2c="
	input := "thequickbrownfoxjumpsoverthelazydog"

	hex := []byte(input)
	encoded := b64.Encode(hex)
	actual := util.B64toa(encoded)
	if expected != actual {
		fmt.Println("Expected:", expected, "Actual:", actual)
		t.Fail()
	}
}
Example #3
0
func TestShortLengthStringInput(t *testing.T) {
	expected := "TWFu"
	input := "Man"

	hex := []byte(input)
	encoded := b64.Encode(hex)
	actual := util.B64toa(encoded)
	if expected != actual {
		fmt.Println("Expected:", expected, "Actual:", actual)
		t.Fail()
	}
}
Example #4
0
func TestMediumLengthHexInput(t *testing.T) {
	expected := "SSdtIGtp"
	input := "49276d206b69"

	hex := util.Atoh(input)
	encoded := b64.Encode(hex)
	actual := util.B64toa(encoded)
	if expected != actual {
		fmt.Println("Expected:", expected, "Actual:", actual)
		t.Fail()
	}
}
Example #5
0
func TestChallenge1(t *testing.T) {
	expected := "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t"
	input := "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"

	hex := util.Atoh(input)
	encoded := b64.Encode(hex)
	actual := util.B64toa(encoded)
	if expected != actual {
		fmt.Println("Expected:", expected, "Actual:", actual)
		t.Fail()
	}
}
Example #6
0
func TestPaddingOne(t *testing.T) {
	var input, expected, actual string
	input = "leasure."
	expected = "bGVhc3VyZS4="

	hex := []byte(input)
	encoded := b64.Encode(hex)
	actual = util.B64toa(encoded)

	if expected != actual {
		fmt.Println("Expected:", expected, "Actual:", actual)
		t.Fail()
	}
}
Example #7
0
func TestPaddingTwo(t *testing.T) {
	var input, expected, actual string
	input = "easure."
	expected = "ZWFzdXJlLg=="

	hex := []byte(input)
	encoded := b64.Encode(hex)
	actual = util.B64toa(encoded)

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