Example #1
0
func main() {

	lines := readLines("./data/4.txt")
	topscore := 0

	var topoutput []byte

	for _, line := range lines {

		raw := hexstring.Decode(line)
		bruteout := bitwise.BRUTEXOR(raw)
		score, key := hexstring.ScoreEnglish(bruteout)
		if score >= topscore {
			topscore = score
			topoutput = bruteout[key]
		}

	}

	output := string(topoutput)

	//Test
	fmt.Printf("Set 1   Challenge 4 \n")

	if output == "one day this nation will rise\n" {

		fmt.Printf("PASS!!\n\n")

	} else {
		fmt.Printf("##FAIL##\n\n")
	}

}
Example #2
0
func main() {

	input := "482169607764216021657364606c"

	raw := hexstring.Decode(input)

	bruteout := bitwise.BRUTEXOR(raw)

	_, key := hexstring.ScoreEnglish(bruteout)

	output := string(bruteout[key])

	//Test
	fmt.Printf("Set 1   Challenge 3 \n")

	if output == "I have a dream" {

		fmt.Printf("PASS!!\n\n")

	} else {
		fmt.Printf("##FAIL##\n\n")
	}

}
Example #3
0
func main() {

	file := io.Read("./data/6.txt")

	raw := base64.Decode(file)

	//fmt.Printf(hexstring.Encode(raw))

	KEYSIZE := 2
	bestkey := 0
	ham := 1000000 // Arbitaray large value
	for KEYSIZE < 40 {

		slice1 := raw[0:KEYSIZE]
		slice2 := raw[KEYSIZE:(KEYSIZE * 2)]

		distance := (bitwise.HAM(slice1, slice2) / KEYSIZE)

		if distance <= ham {
			ham = distance
			bestkey = KEYSIZE

		}
		KEYSIZE++
	}
	print("KEYSIZE: ", bestkey, " HAM: ", ham, "\n")

	KEYSIZE = bestkey

	k := 0

	var finalkey []byte

	for k < KEYSIZE {
		singlekey := 0
		l := 0
		var m []byte

		for l < (len(raw) / KEYSIZE) {

			if (l * KEYSIZE) < (len(raw) - 1) {
				m = append(m, raw[(l*KEYSIZE)+k])
			}

			l++

		}

		bruteout := bitwise.BRUTEXOR(m)

		_, insidekey := hexstring.ScoreEnglish(bruteout)
		singlekey = insidekey
		finalkey = append(finalkey, byte(singlekey))
		//fmt.Printf("%s", bitwise.SBXOR(m, byte(singlekey)))

		m = nil
		k++
	}
	fmt.Printf("-----------------------------------------------------\n")
	fmt.Printf("%s\n", finalkey)
	fmt.Printf("-----------------------------------------------------")
	print("\n")

	//finaloutput := bitwise.RXOR(raw, finalkey)

	//print(string(finaloutput))

	// Hamming Test
	input1 := "@ @ @ @ @ @ @ @ @ !"
	input2 := " @ @ @ @ @ @ @ @ @ "

	testhamming := bitwise.HAM([]byte(input1), []byte(input2))

	if testhamming == 37 {
		print("\n\nPass Hamming Test\n\n")
	} else {
		print("\n\n###FAIL###\n\n")
	}

	//Test
	//fmt.Printf("Set 1   Challenge 6 \n")

	testinput := "f0f0f0"

	testraw := hexstring.Decode(testinput)

	testoutput := base64.Encode(testraw)

	testreverse := base64.Decode(testoutput)

	testcooked := hexstring.Encode(testreverse)

	if testcooked == testinput {

		//fmt.Printf("DING!!!!\n\n")
	}

}