From 7947f245cf3d14e92992199b8662fce3866972b1 Mon Sep 17 00:00:00 2001 From: hanemile Date: Mon, 19 Nov 2018 16:07:17 +0100 Subject: . --- main.go | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..13a1844 --- /dev/null +++ b/main.go @@ -0,0 +1,73 @@ +package main + +import ( + "bufio" + "fmt" + "git.darknebu.la/emile/Substitution-Cracker/structs" + "os" +) + +/* + Goal: Make Chaining ok + + 1. Pack the original String into a channel + 2. Use one of the methods to decrypt (convert type (ascii, dec, hex, bin, ...), base64, rot-n, ...) + 3. Check (letter freq, n-grams, ...) + 4. if not final, goto 2 +*/ + +func main() { + // Get the Ciphertext input + var ciphertext structs.Ciphertext = getCipherText() + mainChannel := make(chan structs.Ciphertext, 100) + + ciphertext.DecodeRotN(mainChannel) + FrequencyAnalysisOnChannel(mainChannel) + BiGramAnalysisOnChannel(mainChannel) + + // Get all elements from the Channel and print them + mainChannelLength := len(mainChannel) + for i := 0; i < mainChannelLength; i++ { + (<-mainChannel).Println() + } +} + +// Read from ST +func getCipherText() structs.Ciphertext { + reader := bufio.NewReader(os.Stdin) + fmt.Print("Enter ciphertext: ") + text, _ := reader.ReadString('\n') + return structs.Ciphertext{Text: text} +} + +// Run a Frequency Analysis on all Elements inside a given channel +func FrequencyAnalysisOnChannel(mainChannel chan structs.Ciphertext) { + + // Generate a FrequencyMap + mainChannelLength := len(mainChannel) + for i := 0; i < mainChannelLength; i++ { + (<-mainChannel).GenFrequencyMap(mainChannel) + } + + // Analyze the FrequencyMap + //mainChannelLength = len(mainChannel) + //for i := 0; i < mainChannelLength; i++ { + // (<- mainChannel).AnalyzeFrequencyMap(mainChannel) + //} +} + +// Run a BiGramAnalysis on all Elements inside a given channel +func BiGramAnalysisOnChannel(mainChannel chan structs.Ciphertext) { + + // Generate a BiGramMap + mainChannelLength := len(mainChannel) + for i := 0; i < mainChannelLength; i++ { + (<-mainChannel).GenBiGramMap(mainChannel) + } + + // Analyze the BiGramMap + //mainChannelLength = len(mainChannel) + //for i := 0; i < mainChannelLength; i++ { + // (<- mainChannel).AnalyzeBiGramMap(mainChannel) + //} +} -- cgit 1.4.1