func main() {
	inputfile := "resources/4.txt"

	// Open input file
	file, err := os.Open(inputfile)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer file.Close()

	// Loop over file lines
	var best *xor.Decryption
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line, _ := conversion.HexToBytes(scanner.Text())

		decryption, _ := xor.BestByteDecryption(line)

		if best == nil || decryption.Score < best.Score {
			best = decryption
		}
	}

	fmt.Println("Line:", conversion.BytesToHex(best.Input))
	fmt.Println("Key:", string(best.Key))
	fmt.Println("Output:", string(best.Output))
}
func main() {
	inputfile := "resources/6.txt"

	// Read input file
	input, err := ioutil.ReadFile(inputfile)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	input = conversion.Base64BytesToBytes(input)

	samples := 15
	ka, err := analysis.BestKeysize(input, samples)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	key := make([]byte, ka.Keysize)
	blocks := conversion.TransposeBlocks(input, ka.Keysize)
	for i := 0; i < ka.Keysize; i++ {
		decrypt, _ := xor.BestByteDecryption(blocks[i])
		key[i] = decrypt.Key[0]
	}

	if result, err := xor.Apply(input, key); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Key:", string(key))
		fmt.Println("Output:", string(result))
	}
}
func main() {
	input := "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"

	if a, err := conversion.HexToBytes(input); err != nil {
		fmt.Println(err)
	} else if result, err := xor.BestByteDecryption(a); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Input:", input)
		fmt.Println("Key:", result.Key)
		fmt.Println("Output:", string(result.Output))
	}
}