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() {
	input := `Burning 'em, if you ain't quick and nimble
I go crazy when I hear a cymbal`
	key := "ICE"

	if result, err := xor.Apply([]byte(input), []byte(key)); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Input:", input)
		fmt.Println("Key:", key)
		fmt.Println("Output:", conversion.BytesToHex(result))
	}
}
Ejemplo n.º 3
0
func main() {
	inputa := "1c0111001f010100061a024b53535009181c"
	inputb := "686974207468652062756c6c277320657965"

	if a, err := conversion.HexToBytes(inputa); err != nil {
		fmt.Println(err)
	} else if b, err := conversion.HexToBytes(inputb); err != nil {
		fmt.Println(err)
	} else if result, err := xor.ApplyFixed(a, b); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Input 1:", inputa)
		fmt.Println("Input 2:", inputb)
		fmt.Println("Output:", conversion.BytesToHex(result))
	}
}