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
|
||||
|
||||
|
|
|
@ -35,18 +35,14 @@ func (l letterList) Swap(i, j int) {
|
|||
}
|
||||
|
||||
const LettersInTheAlphabet = 26
|
||||
|
||||
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',
|
||||
}
|
||||
const startUpperCase = 65
|
||||
|
||||
var letters = make([]letter, LettersInTheAlphabet)
|
||||
|
||||
func initLetterStruct() {
|
||||
for index := range alphabet {
|
||||
letters[index].upperCase = string(alphabet[index])
|
||||
letters[index].lowerCase = string(alphabet[index] + 32)
|
||||
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||
letters[i].upperCase = string(rune(startUpperCase + i))
|
||||
letters[i].lowerCase = string(rune(startUpperCase + i + 32))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,24 +56,24 @@ func readFile(relativePath string) string {
|
|||
|
||||
func countLetters(inputText string) int {
|
||||
totalCount := 0
|
||||
for index := range alphabet {
|
||||
letters[index].count +=
|
||||
strings.Count(inputText, letters[index].lowerCase) +
|
||||
strings.Count(inputText, letters[index].upperCase)
|
||||
totalCount += letters[index].count
|
||||
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||
letters[i].count +=
|
||||
strings.Count(inputText, letters[i].lowerCase) +
|
||||
strings.Count(inputText, letters[i].upperCase)
|
||||
totalCount += letters[i].count
|
||||
}
|
||||
return totalCount
|
||||
}
|
||||
|
||||
func calculateFrequency(totalCount int) {
|
||||
for index := range alphabet {
|
||||
letters[index].frequency = percent.PercentOf(letters[index].count, totalCount)
|
||||
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||
letters[i].frequency = percent.PercentOf(letters[i].count, totalCount)
|
||||
}
|
||||
}
|
||||
|
||||
func printResult() {
|
||||
for index := range alphabet {
|
||||
l := letters[index]
|
||||
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||
l := letters[i]
|
||||
fmt.Printf(
|
||||
"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,
|
||||
|
@ -87,8 +83,8 @@ func printResult() {
|
|||
|
||||
func plotResult() {
|
||||
var count plotter.Values
|
||||
for index := range alphabet {
|
||||
count = append(count, float64(letters[index].count))
|
||||
for i := 0; i < LettersInTheAlphabet; i++ {
|
||||
count = append(count, float64(letters[i].count))
|
||||
}
|
||||
p := plot.New()
|
||||
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}
|
||||
|
||||
\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