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() { 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)) } }
func main() { inputfile := "resources/8.txt" // Open input file file, err := os.Open(inputfile) if err != nil { fmt.Println(err) os.Exit(1) } defer file.Close() scanner := bufio.NewScanner(file) for scanner.Scan() { line := scanner.Text() l, _ := conversion.HexToBytes(line) m := 0 for x := 0; x < len(l); x += 16 { matches := 0 for i := 0; i < len(l); i += 16 { if bytes.Equal(l[x:x+16], l[i:i+16]) { matches++ } } if matches > 1 { m++ } } if m > 0 { fmt.Println("Detected", m, "repetitions:", line) } } }
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)) } }