about summary refs log tree commit diff
path: root/main.go
blob: 13a1844cc0ef765a51e6daf4583c83ff284fa4d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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)
	//}
}