start docu
This commit is contained in:
parent
e2db0aca19
commit
32b8025fda
4 changed files with 31 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
||||||
module analyze
|
module analyse
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
|
|
|
@ -35,18 +35,14 @@ func (l letterList) Swap(i, j int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const LettersInTheAlphabet = 26
|
const LettersInTheAlphabet = 26
|
||||||
|
const startUpperCase = 65
|
||||||
var alphabet = [LettersInTheAlphabet]rune{
|
|
||||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
||||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
||||||
}
|
|
||||||
|
|
||||||
var letters = make([]letter, LettersInTheAlphabet)
|
var letters = make([]letter, LettersInTheAlphabet)
|
||||||
|
|
||||||
func initLetterStruct() {
|
func initLetterStruct() {
|
||||||
for index := range alphabet {
|
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||||
letters[index].upperCase = string(alphabet[index])
|
letters[i].upperCase = string(rune(startUpperCase + i))
|
||||||
letters[index].lowerCase = string(alphabet[index] + 32)
|
letters[i].lowerCase = string(rune(startUpperCase + i + 32))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,24 +56,24 @@ func readFile(relativePath string) string {
|
||||||
|
|
||||||
func countLetters(inputText string) int {
|
func countLetters(inputText string) int {
|
||||||
totalCount := 0
|
totalCount := 0
|
||||||
for index := range alphabet {
|
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||||
letters[index].count +=
|
letters[i].count +=
|
||||||
strings.Count(inputText, letters[index].lowerCase) +
|
strings.Count(inputText, letters[i].lowerCase) +
|
||||||
strings.Count(inputText, letters[index].upperCase)
|
strings.Count(inputText, letters[i].upperCase)
|
||||||
totalCount += letters[index].count
|
totalCount += letters[i].count
|
||||||
}
|
}
|
||||||
return totalCount
|
return totalCount
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateFrequency(totalCount int) {
|
func calculateFrequency(totalCount int) {
|
||||||
for index := range alphabet {
|
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||||
letters[index].frequency = percent.PercentOf(letters[index].count, totalCount)
|
letters[i].frequency = percent.PercentOf(letters[i].count, totalCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func printResult() {
|
func printResult() {
|
||||||
for index := range alphabet {
|
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||||
l := letters[index]
|
l := letters[i]
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"The letter %s (%s) occurs %d times in the text and the frequencyArray in percent is %0.2f\n",
|
"The letter %s (%s) occurs %d times in the text and the frequencyArray in percent is %0.2f\n",
|
||||||
l.upperCase, l.lowerCase, l.count, l.frequency,
|
l.upperCase, l.lowerCase, l.count, l.frequency,
|
||||||
|
@ -87,8 +83,8 @@ func printResult() {
|
||||||
|
|
||||||
func plotResult() {
|
func plotResult() {
|
||||||
var count plotter.Values
|
var count plotter.Values
|
||||||
for index := range alphabet {
|
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||||
count = append(count, float64(letters[index].count))
|
count = append(count, float64(letters[i].count))
|
||||||
}
|
}
|
||||||
p := plot.New()
|
p := plot.New()
|
||||||
p.Title.Text = "Letter count"
|
p.Title.Text = "Letter count"
|
||||||
|
|
BIN
Lab04/documentation/images/part1/initAlphabet.png
Normal file
BIN
Lab04/documentation/images/part1/initAlphabet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
|
@ -1,2 +1,17 @@
|
||||||
\section{Part 1: Substitution Cipher}
|
\section{Part 1: Substitution Cipher}
|
||||||
|
|
||||||
|
\subsection{Analysing}
|
||||||
|
|
||||||
|
Als Programmiersprache wurde Go\footnote{\href{https://go.dev/}{https://go.dev/}} ausgewählt. Das Analysetool soll jeden Buchstaben eines Textes auf Häufigkeit untersuchen.
|
||||||
|
|
||||||
|
Im Prgram wird mit einem Strukt Array gearbeitet. Darin wird der Buchstabe swowohl groß, als auch klein als String abgespeichert. Außerdem wird die dazugehörige Anzahl mit der Häufigkeit abgespeichert. Dadurch kann nach dem Durchlauf der Datensatz einfach sortiert werden.
|
||||||
|
|
||||||
|
Das Alphabet wird im “Unicode Code Point” genutzt damit es einfach verglichen werden kann. Zum Start des Programmes wird das Alphabet in der ``LetterList'' initialisiert.
|
||||||
|
|
||||||
|
\begin{figure}[H]
|
||||||
|
\begin{center}
|
||||||
|
\includegraphics[width=0.6\textwidth]{part1/initAlphabet}
|
||||||
|
\caption{Initialisierung mit Unicode}
|
||||||
|
\label{fig:Initialisierung mit Unicode}
|
||||||
|
\end{center}
|
||||||
|
\end{figure}
|
||||||
|
|
Reference in a new issue