Skip to content
Snippets Groups Projects
Commit 9151ff82 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Vorbereitung 29.4.2025

parent e82c553a
Branches
No related tags found
No related merge requests found
../common/Zeichen_123.pdf
\ No newline at end of file
File added
% ad-20250429.pdf - Lecture Slides on Algorithms and Data Structures in C/C++
% Copyright (C) 2018-2024, 2025 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Diffie-Hellman, Parität, CRC, Hadamard-Code, RAID
\documentclass[10pt,t]{beamer}
\usepackage{pgslides}
\usepackage{tikz}
%\usepackage{rotating}
\newcommand{\underconstruction}{%
\begin{picture}(0,0)
\color{black}
\put(6,-2.2){\makebox(0,0)[b]{\includegraphics[width=1.5cm]{Zeichen_123.pdf}}}
\put(6,-2.5){\makebox(0,0)[t]{\shortstack{Änderungen\\vorbehalten}}}
\end{picture}}
\title{Algorithmen und Datenstrukturen in C/C++}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{29.\ April 2025}
\begin{document}
\maketitleframe
\setcounter{section}{2}
\section{Langzahl-Arithmetik}
\begin{frame}
\showsection
Problem: Rechnen mit ganzen Zahlen, die größer sind als das,\\
was der Rechner normalerweise verarbeiten kann
\bigskip
{\large\textbf{Aufgabe (gelöst): Addition langer Zahlen}\par}
\smallskip
\begin{itemize}
\item[(a)]
Überlegen Sie sich eine Datenstruktur, um eine lange Zahl zu speichern.
\item[(b)]
Schreiben Sie eine Funktion, die zwei lange Zahlen addiert.
\end{itemize}
\smallskip
Hinweis: "`schriftlich"' rechnen
\end{frame}
\begin{frame}
\showsection
Problem: Rechnen mit ganzen Zahlen, die größer sind als das,\\
was der Rechner normalerweise verarbeiten kann
\medskip
\begin{itemize}
\item
Grundrechenarten (einschließlich "`modulo"'):\\
"`schriftlich"' rechnen
\item
\href{https://de.wikipedia.org/wiki/Binäre_Exponentiation}%
{binäre Exponentiation}:\\
Basis fortlaufend quadrieren, ggf.\ damit multiplizieren\\
Beispiel: $x^9 = ((x^2)^2)^2 \cdot x$
\item
Suche nach $d$ mit $d\cdot e~\text{mod}~N = 1$:\\
\href{https://de.wikipedia.org/wiki/Erweiterter_euklidischer_Algorithmus}%
{erweiterter euklidischer Algorithmus}\quad
$\longleftarrow$ \textbf{Aufgabe (gelöst)}
\smallskip
\arrowitem
RSA
\end{itemize}
\end{frame}
\section{Kryptographie}
\subsectionnonumber{\boldmath 4.$(x^2 - 1)$\quad Der Herr der Ringe: Manchmal ist $1 + 1 = 0$.}
\subsubsectionnonumber{\boldmath 4.$(x^2 - 1).x$\quad Motivation}
\begin{frame}
\showsection
% \pause
\showsubsectionnonumber
% \pause
\showsubsubsectionnonumber
Man kann auch mit sehr merkwürdigen Objekten\\
wie mit "`ganz normalen"' Zahlen rechnen.
% \pause
\bigskip
Anwendungen:
\begin{itemize}
\item Funktionsweise von Computern (\textarrow\ Rechnertechnik)
\item Fehlererkennung
\item Fehlerkorrektur
\item Verschlüsselung
\item Digitale Signaturen
\end{itemize}
\end{frame}
\subsubsectionnonumber{\boldmath 4.$(x^2 - 1).(x + 1)$\quad Gruppen}
\begin{frame}
\showsection
\showsubsectionnonumber
\showsubsubsectionnonumber
\textbf{Definition:}
Sei $G$ eine Menge, $*$ eine Verknüpfung auf $G$.
Wenn
\begin{itemize}
\item
$\forall a, b, c \in G$: $(a * b) * c = a * (b * c)$ \quad (Assoziativgesetz),
\item
$\exists e \in G$: $\forall a \in G$: $a * e = e * a = a$ \quad (neutrales Element),
\item
$\forall a \in G$: $\exists a^{-1} \in G$: $a * a^{-1} = a^{-1} * a = e$ \quad (inverses Element),
\end{itemize}
dann heißt $(G,*)$ eine \newterm{Gruppe}.
% \pause
\bigskip
\textbf{Definition:}
Sei $(G,*)$ eine Gruppe.
Wenn zusätzlich
\begin{itemize}
\item
$\forall a, b \in G$: $a * b = b * a$ \quad (Kommutativgesetz),
\end{itemize}
dann heißt $(G,*)$ eine \newterm{kommutative Gruppe}.
\end{frame}
\subsubsectionnonumber{\boldmath 4.$(x^2 - 1).(x + 2)$\quad Ringe}
\begin{frame}
% \showsection
\showsubsectionnonumber
\showsubsubsectionnonumber
\textbf{Definition:}
Sei $R$ eine Menge; seien $+$ und $\cdot$ Verknüpfungen auf $R$.
Wenn
\begin{itemize}
\item
$(R,+)$ eine kommutative Gruppe ist,
\item
$\forall a, b, c \in R$: $(a \cdot b) \cdot c = a \cdot (b \cdot c)$ \quad (Assoziativgesetz),
\item
$\forall a, b, c \in R$: $(a + b)\cdot c = a\cdot c + b\cdot c$
und $a\cdot(b + c) = a\cdot b + a\cdot c$ \quad (Distributivgesetze),
\end{itemize}
dann heißt $(R,+,\cdot)$ ein \newterm{Ring}.
% \pause
\bigskip
\textbf{Definition:}
Sei $(R,+,\cdot)$ ein Ring.
Wenn zusätzlich
\begin{itemize}
\item
$\forall a, b \in R$: $a \cdot b = b \cdot a$ \quad (Kommutativgesetz),
\end{itemize}
dann heißt $(R,+,\cdot)$ ein \newterm{kommutativer Ring}.
% \pause
\bigskip
\textbf{Definition:}
Sei $(R,+,\cdot)$ ein (kommutativer) Ring.
Wenn zusätzlich
\begin{itemize}
\item
ein $e \in R$ existiert, so daß für alle $a \in R$ gilt: $a \cdot e = e \cdot a = a$\\
(neutrales Element),
\end{itemize}
dann heißt $(R,+,\cdot)$ ein \newterm{(kommutativer) Ring mit 1}.
\vspace*{-1cm}
\end{frame}
\subsubsectionnonumber{\boldmath 4.$(x^2 - 1).(x + 3)$\quad Körper}
\begin{frame}
% \showsection
\showsubsectionnonumber
\showsubsubsectionnonumber
\textbf{Definition:}
Sei $K$ eine Menge; seien $+$ und $\cdot$ Verknüpfungen auf $K$.
Wenn
\begin{itemize}
\item
$(K,+,\cdot)$ ein Ring mit 1 ist und
\item
$(K \backslash \{0\},\cdot)$ eine kommutative Gruppe ist,
\end{itemize}
dann heißt $(K,+,\cdot)$ ein \newterm{Körper}.
\end{frame}
\subsectionnonumber{\boldmath 4.$x^2$\quad Anwendung: RSA}
\begin{frame}
\showsubsectionnonumber
\vspace{-\medskipamount}
\begin{itemize}
\item
Öffentlicher Schlüssel: $N = p\cdot q$, $e$
\item
Geheimer Schlüssel: $n = (p - 1)\cdot(q - 1)$, $d$ mit $d\cdot e = 1 \,\text{mod}\, n$
\item
Verschlüsselung: $c = m^e \,\text{mod}\, N$
\item
Entschlüsselung: $m = c^d \,\text{mod}\, n$
\end{itemize}
\medskip
Rechnungen \emph{modulo\/} einer Primzahl $N$ (oder einer Fast-Primzahl $n$\,\mbox{;--)}\\
funktionieren "`fast"' wie in $\mathbb{R}$.
\smallskip
In $\mathbb{R}$ gilt: Wenn $d\cdot e = 1$, dann:\quad
\begin{math}\displaystyle
c^d = (m^e)^d = m^{e\cdot d} = m^1 = m.
\end{math}
\smallskip
\textcolor{gray}{(modulo $N$ bzw.\ $n$: Satz von Euler -- siehe Tafelbild vom 15.\,4.\,2025)}
\medskip
\begin{itemize}
\item
Für die Berechnung von $d$ aus $n$ gibt es den\\
erweiterten euklidischen Algorithmus in $\mathcal{O}\bigl((\log n)^2\bigr)$.\\
($\log n$ = Anzahl der Ziffern (Bits) von $n$)
\item
Für die Berechnung von $n,d$ aus $N,e$ (Primfaktorzerlegung) gibt es\\[2pt]
\emph{keinen\/} effizienten Algorithmus.
\textcolor{gray}{-- bestenfalls etwa
$\mathcal{O}\bigl(2^{\sqrt{\log n\,\cdot\,\log\log n}}\bigr)$}
\arrowitem
RSA ist sicher.
\pause
\item
\textcolor{bored}{Quantencomputer}
berechnen $n$ aus $N$ in $\mathcal{O}\bigl((\log n)^3\bigr)$.
\end{itemize}
\end{frame}
\subsectionnonumber{\boldmath 4.$(x^2 + 1)$\quad Anwendung: Diffie-Hellman-Schlüsselaustausch}
\begin{frame}
\showsubsectionnonumber
\vspace{-\medskipamount}
\begin{itemize}
\item
Separate geheime Schlüssel: $a$, $b$
\item
Öffentliche Schlüssel: $N$, $g$, $A = g^a \,\text{mod}\, N$, $B = g^b \,\text{mod}\, N$
\end{itemize}
\medskip
Rechnungen \emph{modulo\/} einer Primzahl $N$\\
funktionieren "`fast"' wie in $\mathbb{R}$.
\smallskip
Gemeinsamer geheimer Schlüssel: $B^a = g^{a\cdot b} = A^b$
\pause
\medskip
\begin{itemize}
\item
Für die Berechnung von $B^a$ und $A^b$ gibt es die\\
binäre Exponentiation in $\mathcal{O}\bigl((\log n)^2\bigr)$.\\
($\log n$ = Anzahl der Ziffern (Bits) von $a$ bzw.\ $b$)
\item
Für die Berechnung von $a$ aus $A,g$ bzw.\ von $b$ aus $B,g$\\
(diskreter Logarithmus) gibt es \emph{keinen\/} effizienten Algorithmus.
\arrowitem
Diffie-Hellman ist sicher.
\end{itemize}
\end{frame}
\subsectionnonumber{\boldmath 4.$(x^2 + 2)$\quad Weitere Anwendungen}
\begin{frame}
\showsubsectionnonumber
\vspace{-\medskipamount}
\begin{itemize}
\item
Fehlererkennung und -korrektur: Reed-Solomon-Code\\
(siehe Tafelbild von 15.\,4.\,2025)
\item
Fehlererkennung in Hardware: Parität
\item
Fehlererkennung in Hardware: Cyclic Redundancy Check (CRC)
\item
Fehlererkennung und -korrektur in Hardware: Hadamard-Code
\item
Ausfallkorrektur: RAID
\end{itemize}
\end{frame}
\iffalse
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\underconstruction
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad}}}
% \item[\textbf{i}] \textbf{Gesellschaftliche Auswirkungen\\
% von Algorithmen und Datenstrukturen}
\item[\textbf{2}] \textbf{Datenorganisation}
\item[\textbf{3}] \textbf{Optimierung}
\item[\textbf{4}] \textbf{Hardwarenahe Algorithmen}
\item[\textbf{5}] \textbf{Datenkodierung}
\color{gray}
\item[\textbf{6}] \textbf{Numerik}
\end{itemize}
\end{frame}
\section{Einführung in C++}
\addtocounter{subsection}{-1}
\subsection{Was ist C?}
\begin{frame}
\showsection
\showsubsection
Etabliertes Profi-Werkzeug
\begin{itemize}
\item
kleinster gemeinsamer Nenner für viele Plattformen\\
\begin{picture}(0,1)
\color{red}
\put(7.2,0.6){\tikz{\draw[-latex](0.0,0.0)--(0.0,0.4);}}
\put(7.2,0.5){\makebox(0,0)[t]{\color{black}Hardware und/oder Betriebssystem}}
\end{picture}
\item
Hardware direkt ansprechen und effizient einsetzen
\item
\dots\ bis hin zu komplexen Software-Projekten
\medskip
\arrowitem
Man kann Computer vollständig beherrschen.
\end{itemize}
\end{frame}
\begin{frame}
\showsection
\showsubsection
\begin{picture}(0,0)
\put(5.3,-2.5){\makebox(0,0)[tl]{\begin{minipage}{7cm}
\emph{C makes it easy to shoot yourself in the foot.}
\begin{flushright}
Bjarne Stroustrup, ca.~1986\\
\href{http://www.stroustrup.com/bs_faq.html\#really-say-that}%
{\nolinkurl{http://www.stroustrup.com/bs_faq.html}\\
\nolinkurl{\#really-say-that}}
\end{flushright}
\end{minipage}}}
\end{picture}%
Etabliertes Profi-Werkzeug
\begin{itemize}
\item
kleinster gemeinsamer Nenner für viele Plattformen
\item
Hardware direkt ansprechen und effizient einsetzen
\item
\dots\ bis hin zu komplexen Software-Projekten
\item
leistungsfähig, aber gefährlich
\end{itemize}
\medskip
"`High-Level-Assembler"'
\begin{itemize}
\item
kein "`Fallschirm"'
\item
kompakte Schreibweise
\end{itemize}
\medskip
Unix-Hintergrund
\begin{itemize}
\item
Baukastenprinzip
\item
konsequente Regeln
\item
kein "`Fallschirm"'
\end{itemize}
\end{frame}
\subsection{Was ist C++?}
\begin{frame}
\showsection
\showsubsection
\begin{picture}(0,0)
\put(6.3,-0.2){\makebox(0,0)[tl]{\begin{minipage}{6cm}
\emph{C++ is a better C.}
\begin{flushright}
Bjarne Stroustrup, Autor von C++\\
\url{http://www.stroustrup.com/C++.html}
\end{flushright}
\end{minipage}}}
\put(5.3,-2.5){\makebox(0,0)[tl]{\begin{minipage}{7cm}
\emph{C makes it easy to shoot yourself in the foot;\\
C++ makes it harder, but when you do\\
it blows your whole leg off.}
\begin{flushright}
Bjarne Stroustrup, Autor von C++, ca.~1986\\
\href{http://www.stroustrup.com/bs_faq.html\#really-say-that}%
{\nolinkurl{http://www.stroustrup.com/bs_faq.html}\\
\nolinkurl{\#really-say-that}}
\end{flushright}
\end{minipage}}}
\end{picture}%
Etabliertes Profi-Werkzeug
\begin{itemize}
\item
kompatibel zu C
\end{itemize}
\medskip
C++ unterstützt
\begin{itemize}
\item
\newterm{objektorientierte\\
Programmierung}
\item
\newterm{Datenabstraktion}
\item
\newterm{generische\\
Programmierung}
\end{itemize}
\vspace{0cm plus 1 filll}
\textbf{Motivation:}\\[\smallskipamount]
Vermeidung unsicherer Techniken,\\
insbesondere von Präprozessor-Konstruktionen und Zeigern,\\
unter Beibehaltung der Effizienz
\end{frame}
\subsection{Elementare Neuerungen in C++ gegenüber C}
\begin{frame}[fragile]
\showsubsection
\begin{itemize}
\pause
\item
Kommentare mit \lstinline{//}
\pause
\item
Konstante:
\begin{onlyenv}<3>
\begin{lstlisting}[gobble=10]
const int answer = 42;
\end{lstlisting}
\end{onlyenv}
\begin{lstlisting}[gobble=8]
const int n = 5;
int prime[n] = { 2, 3, 5, 7, 11 };
\end{lstlisting}
\pause
\item
Ab C++11: \lstinline{constexpr}-Funktionen\\
% \only<1->{{\color{red}\dots\ anscheinend auch ohne "`constexpr"' \dots}\\}
C++11: darf nur aus einem einzigen \lstinline{return}-Statement bestehen\\
\textarrow\ \lstinline{?:} statt \lstinline{if}, Rekursion statt Schleife\\
C++-14: auch Verzweigungen und Schleifen erlaubt
\pause
\item
leere Parameterliste: \lstinline{void} optional\\
in C: ohne \lstinline{void} = Parameterliste wird nicht geprüft
\pause
\item
Operatoren \lstinline{new} und \lstinline{delete}\\
als Alternative zu den Funktionen \lstinline{malloc()} und \lstinline{free()}
\end{itemize}
\end{frame}
\fi
\end{document}
../common/logo-hochschule-bochum-cvh-text-v3.pdf
\ No newline at end of file
../common/logo-hochschule-bochum-de-narrow.pdf
\ No newline at end of file
../common/pgslides.sty
\ No newline at end of file
...@@ -20,6 +20,7 @@ Vortragsfolien und Beispiele: ...@@ -20,6 +20,7 @@ Vortragsfolien und Beispiele:
* [25.03.2025: Einführung, Arrays und Zeiger für Fortgeschrittene](https://gitlab.cvh-server.de/pgerwinski/ad/raw/2025ss/20250325/ad-20250325.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/ad/tree/2025ss/20250325/) * [25.03.2025: Einführung, Arrays und Zeiger für Fortgeschrittene](https://gitlab.cvh-server.de/pgerwinski/ad/raw/2025ss/20250325/ad-20250325.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/ad/tree/2025ss/20250325/)
* [01.04.2025: Langzahl-Arithmetik](https://gitlab.cvh-server.de/pgerwinski/ad/raw/2025ss/20250401/ad-20250401.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/ad/tree/2025ss/20250401/) * [01.04.2025: Langzahl-Arithmetik](https://gitlab.cvh-server.de/pgerwinski/ad/raw/2025ss/20250401/ad-20250401.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/ad/tree/2025ss/20250401/)
* [15.04.2025: Langzahl-Arithmetik, Einführung in die Kryptographie](https://gitlab.cvh-server.de/pgerwinski/ad/raw/2025ss/20250415/ad-20250415.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/ad/tree/2025ss/20250415/) * [15.04.2025: Langzahl-Arithmetik, Einführung in die Kryptographie](https://gitlab.cvh-server.de/pgerwinski/ad/raw/2025ss/20250415/ad-20250415.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/ad/tree/2025ss/20250415/)
* [29.04.2025: Diffie-Hellman, Parität, CRC, Hadamard-Code, RAID](https://gitlab.cvh-server.de/pgerwinski/ad/raw/2025ss/20250429/ad-20250429.pdf) [**(Beispiele)**](https://gitlab.cvh-server.de/pgerwinski/ad/tree/2025ss/20250429/)
* [alle in 1 Datei](https://gitlab.cvh-server.de/pgerwinski/ad/raw/2025ss/ad-slides-2025ss.pdf) * [alle in 1 Datei](https://gitlab.cvh-server.de/pgerwinski/ad/raw/2025ss/ad-slides-2025ss.pdf)
Tafelbilder: Tafelbilder:
......
No preview for this file type
...@@ -10,10 +10,12 @@ ...@@ -10,10 +10,12 @@
\includepdf[pages=1]{common/ad-slides-title-2025ss.pdf} \includepdf[pages=1]{common/ad-slides-title-2025ss.pdf}
\pdfbookmark[1]{Wichtiger Hinweis}{Hinweis} \pdfbookmark[1]{Wichtiger Hinweis}{Hinweis}
\includepdf[pages=2-]{common/ad-slides-title-2025ss.pdf} \includepdf[pages=2-]{common/ad-slides-title-2025ss.pdf}
\pdfbookmark[1]{25.03.2025: Einführung}{20250325} \pdfbookmark[1]{25.03.2025: Einführung, Arrays und Zeiger für Fortgeschrittene}{20250325}
\includepdf[pages=-]{20250325/ad-20250325.pdf} \includepdf[pages=-]{20250325/ad-20250325.pdf}
\pdfbookmark[1]{01.04.2025: Einführung in die Kryptographie}{20250401} \pdfbookmark[1]{01.04.2025: Langzahl-Arithmetik}{20250401}
\includepdf[pages=-]{20250401/ad-20250401.pdf} \includepdf[pages=-]{20250401/ad-20250401.pdf}
\pdfbookmark[1]{15.04.2025: Einführung in die Kryptographie}{20250415} \pdfbookmark[1]{15.04.2025: Langzahl-Arithmetik, Einführung in die Kryptographie}{20250415}
\includepdf[pages=-]{20250415/ad-20250415.pdf} \includepdf[pages=-]{20250415/ad-20250415.pdf}
\pdfbookmark[1]{29.04.2025: Diffie-Hellman, Parität, CRC, Hadamard-Code, RAID}{20250429}
\includepdf[pages=-]{20250429/ad-20250429.pdf}
\end{document} \end{document}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment