Add intro-crypto exercise 04
Some checks failed
the build failed

This commit is contained in:
Valentin Brandl
2018-11-15 11:54:38 +01:00
parent e432146791
commit ca6e6e1015
68 changed files with 679 additions and 0 deletions

View File

@ -0,0 +1,475 @@
\documentclass[12pt,a4paper,german]{article}
\usepackage{url}
%\usepackage{graphics}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{pifont}
\usepackage{ngerman}
\usepackage{float}
\usepackage{diagbox}
\usepackage[latin1]{inputenc}
\usepackage{geometry}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{delarray}
% \usepackage{minted}
\usepackage{csquotes}
\usepackage{graphicx}
\usepackage{epsfig}
\usepackage{longtable}
\usepackage{paralist}
\geometry{left=2.0cm,textwidth=17cm,top=3.5cm,textheight=23cm}
\graphicspath{.}
%%%%%%%%%% Fill out the the definitions %%%%%%%%%
\def \name {Valentin Brandl} %
\def \matrikel {108018274494} %
% \def \pname {Vorname2 Nachname2} %
% \def \pmatrikel {Matrikelnummer2} %
\def \gruppe {Gruppe 193} %
\def \uebung {4} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DO NOT MODIFY THIS HEADER
\newcommand{\hwsol}{
\vspace*{-2cm}
\noindent \matrikel \quad \name \hfill Gruppe:\gruppe \\
% \noindent \pmatrikel \quad \pname \\
\begin{center}{\Large \bf L\"osung f\"ur \"Ubung \# \uebung}\end{center}
}
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\begin{document}
%Import header
\hwsol
\section*{Aufgabe 1}
Grad $m = 6 \Rightarrow 2^m - 1 = 2^6 - 1 = 63$.
Zust<EFBFBD>nde und Tabellen wurden mit dem angeh<65>ngten Code generiert.
%{{{ a1
\begin{enumerate}[a)]
\item $x^5 + x^4 + x^2 + x + 1$
\begin{figure}[h]
\includegraphics[width=\textwidth]{1a}
\caption{Schaltbild des Schieberegisters f<>r 1a)}
\end{figure}
IV: $1 0 0 0 0 0$
\begin{tabular}{|cccccc|c|}
$x_5$ & $x_4$ & $x_3$ & $x_2$ & $x_1$ & $x_0$ & Output \\\hline
1 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 \\
1 & 0 & 1 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 0 & 0 \\
1 & 0 & 0 & 1 & 0 & 1 & 1 \\
0 & 1 & 0 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 1 & 1 \\
1 & 0 & 0 & 1 & 0 & 0 & 0 \\
1 & 1 & 0 & 0 & 1 & 0 & 0 \\
0 & 1 & 1 & 0 & 0 & 1 & 1 \\
0 & 0 & 1 & 1 & 0 & 0 & 0 \\
1 & 0 & 0 & 1 & 1 & 0 & 0 \\
0 & 1 & 0 & 0 & 1 & 1 & 1 \\
1 & 0 & 1 & 0 & 0 & 1 & 1 \\
1 & 1 & 0 & 1 & 0 & 0 & 0 \\
0 & 1 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 1 & 0 & 1 & 1 \\
0 & 0 & 0 & 1 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 1 & 1 \\
0 & 0 & 0 & 0 & 0 & 1 & 1 \\
\underline{1} & \underline{0} & \underline{0} & \underline{0} & \underline{0} & \underline{0} & 0 \\
\end{tabular}
Wiederholung nach 21 Iterationen.
Neuer IV: $1 1 1 1 1 1$
\begin{tabular}{|cccccc|c|}
$x_5$ & $x_4$ & $x_3$ & $x_2$ & $x_1$ & $x_0$ & Output \\\hline
1 & 1 & 1 & 1 & 1 & 1 & 1 \\
0 & 1 & 1 & 1 & 1 & 1 & 1 \\
0 & 0 & 1 & 1 & 1 & 1 & 1 \\
1 & 0 & 0 & 1 & 1 & 1 & 1 \\
1 & 1 & 0 & 0 & 1 & 1 & 1 \\
1 & 1 & 1 & 0 & 0 & 1 & 1 \\
0 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 1 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 & 1 & 1 & 1 \\
1 & 0 & 0 & 0 & 1 & 1 & 1 \\
0 & 1 & 0 & 0 & 0 & 1 & 1 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 \\
1 & 0 & 0 & 0 & 1 & 0 & 0 \\
1 & 1 & 0 & 0 & 0 & 1 & 1 \\
0 & 1 & 1 & 0 & 0 & 0 & 0 \\
1 & 0 & 1 & 1 & 0 & 0 & 0 \\
1 & 1 & 0 & 1 & 1 & 0 & 0 \\
1 & 1 & 1 & 0 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 0 & 1 & 1 \\
1 & 1 & 1 & 1 & 1 & 0 & 0 \\
\underline{1} & \underline{1} & \underline{1} & \underline{1} & \underline{1} & \underline{1} & 1 \\
\end{tabular}
Wiederholung wieder nach 21 Iterationen.
$63 - 21 - 21 = 21$ Fehlende Zust<73>nde.
Neuer IV: $1 1 0 0 0 0$
\begin{tabular}{|cccccc|c|}
$x_5$ & $x_4$ & $x_3$ & $x_2$ & $x_1$ & $x_0$ & Output \\\hline
1 & 1 & 0 & 0 & 0 & 0 & 0 \\
1 & 1 & 1 & 0 & 0 & 0 & 0 \\
1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 1 & 1 & 1 & 1 & 0 & 0 \\
1 & 0 & 1 & 1 & 1 & 1 & 1 \\
1 & 1 & 0 & 1 & 1 & 1 & 1 \\
0 & 1 & 1 & 0 & 1 & 1 & 1 \\
1 & 0 & 1 & 1 & 0 & 1 & 1 \\
0 & 1 & 0 & 1 & 1 & 0 & 0 \\
1 & 0 & 1 & 0 & 1 & 1 & 1 \\
0 & 1 & 0 & 1 & 0 & 1 & 1 \\
1 & 0 & 1 & 0 & 1 & 0 & 0 \\
1 & 1 & 0 & 1 & 0 & 1 & 1 \\
1 & 1 & 1 & 0 & 1 & 0 & 0 \\
0 & 1 & 1 & 1 & 0 & 1 & 1 \\
1 & 0 & 1 & 1 & 1 & 0 & 0 \\
0 & 1 & 0 & 1 & 1 & 1 & 1 \\
0 & 0 & 1 & 0 & 1 & 1 & 1 \\
0 & 0 & 0 & 1 & 0 & 1 & 1 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 \\
1 & 0 & 0 & 0 & 0 & 1 & 1 \\
\underline{1} & \underline{1} & \underline{0} & \underline{0} & \underline{0} & \underline{0} & 0 \\
\end{tabular}
Wiederholung wieder nach 21 Iterationen.
$63 - 21 - 21 - 21 = 0$ Fehlende Zust<73>nde. Alle m<>glichen Zust<73>nde wurden erzeugt.
Keine Sequenz maximaler L<>nge aber L<>nge unabh<62>ngig von IV$\Rightarrow$ es liegt ein irreduzibles Polynom
zugrunde
\item $x^5 + x + 1$
\begin{figure}[h]
\includegraphics[width=\textwidth]{1b}
\caption{Schaltbild des Schieberegisters f<>r 1b)}
\end{figure}
IV: $1 0 0 0 0 0$
\begin{longtable}{|cccccc|c|}
$x_5$ & $x_4$ & $x_3$ & $x_2$ & $x_1$ & $x_0$ & Output \\\hline
1 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 \\
1 & 0 & 0 & 0 & 0 & 1 & 1 \\
1 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 1 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 1 & 0 & 0 \\
1 & 0 & 0 & 0 & 1 & 1 & 1 \\
0 & 1 & 0 & 0 & 0 & 1 & 1 \\
1 & 0 & 1 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 0 & 0 \\
1 & 0 & 0 & 1 & 0 & 1 & 1 \\
1 & 1 & 0 & 0 & 1 & 0 & 0 \\
1 & 1 & 1 & 0 & 0 & 1 & 1 \\
1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 1 & 1 & 1 & 1 & 0 & 0 \\
1 & 0 & 1 & 1 & 1 & 1 & 1 \\
0 & 1 & 0 & 1 & 1 & 1 & 1 \\
0 & 0 & 1 & 0 & 1 & 1 & 1 \\
0 & 0 & 0 & 1 & 0 & 1 & 1 \\
1 & 0 & 0 & 0 & 1 & 0 & 0 \\
1 & 1 & 0 & 0 & 0 & 1 & 1 \\
1 & 1 & 1 & 0 & 0 & 0 & 0 \\
0 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 1 & 1 & 0 & 0 \\
1 & 0 & 0 & 1 & 1 & 1 & 1 \\
0 & 1 & 0 & 0 & 1 & 1 & 1 \\
0 & 0 & 1 & 0 & 0 & 1 & 1 \\
1 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 1 & 0 & 0 \\
1 & 0 & 1 & 0 & 0 & 1 & 1 \\
1 & 1 & 0 & 1 & 0 & 0 & 0 \\
0 & 1 & 1 & 0 & 1 & 0 & 0 \\
1 & 0 & 1 & 1 & 0 & 1 & 1 \\
1 & 1 & 0 & 1 & 1 & 0 & 0 \\
1 & 1 & 1 & 0 & 1 & 1 & 1 \\
0 & 1 & 1 & 1 & 0 & 1 & 1 \\
1 & 0 & 1 & 1 & 1 & 0 & 0 \\
1 & 1 & 0 & 1 & 1 & 1 & 1 \\
0 & 1 & 1 & 0 & 1 & 1 & 1 \\
0 & 0 & 1 & 1 & 0 & 1 & 1 \\
1 & 0 & 0 & 1 & 1 & 0 & 0 \\
1 & 1 & 0 & 0 & 1 & 1 & 1 \\
0 & 1 & 1 & 0 & 0 & 1 & 1 \\
1 & 0 & 1 & 1 & 0 & 0 & 0 \\
0 & 1 & 0 & 1 & 1 & 0 & 0 \\
1 & 0 & 1 & 0 & 1 & 1 & 1 \\
0 & 1 & 0 & 1 & 0 & 1 & 1 \\
1 & 0 & 1 & 0 & 1 & 0 & 0 \\
1 & 1 & 0 & 1 & 0 & 1 & 1 \\
1 & 1 & 1 & 0 & 1 & 0 & 0 \\
1 & 1 & 1 & 1 & 0 & 1 & 1 \\
1 & 1 & 1 & 1 & 1 & 0 & 0 \\
1 & 1 & 1 & 1 & 1 & 1 & 1 \\
0 & 1 & 1 & 1 & 1 & 1 & 1 \\
0 & 0 & 1 & 1 & 1 & 1 & 1 \\
0 & 0 & 0 & 1 & 1 & 1 & 1 \\
0 & 0 & 0 & 0 & 1 & 1 & 1 \\
0 & 0 & 0 & 0 & 0 & 1 & 1 \\
\underline{1} & \underline{0} & \underline{0} & \underline{0} & \underline{0} & \underline{0} & 0 \\
\end{longtable}
Wiederholung nach 63 Iterationen, es wurden also eine Sequenz maximaler L<>nge erzeugt $\Rightarrow$ primitives
Polynom liegt zugrunde.
\item $x^5 + x^3 + x^2 + x + 1$
\begin{figure}[h]
\includegraphics[width=\textwidth]{1c}
\caption{Schaltbild des Schieberegisters f<>r 1c)}
\end{figure}
IV: $1 0 0 0 0 0$
\begin{tabular}{|cccccc|c|}
$x_5$ & $x_4$ & $x_3$ & $x_2$ & $x_1$ & $x_0$ & Output \\\hline
1 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 & 0 \\
1 & 0 & 0 & 1 & 0 & 0 & 0 \\
1 & 1 & 0 & 0 & 1 & 0 & 0 \\
1 & 1 & 1 & 0 & 0 & 1 & 1 \\
0 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 1 & 1 & 0 & 0 \\
1 & 0 & 0 & 1 & 1 & 1 & 1 \\
1 & 1 & 0 & 0 & 1 & 1 & 1 \\
0 & 1 & 1 & 0 & 0 & 1 & 1 \\
0 & 0 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 1 & 1 & 1 \\
0 & 0 & 0 & 0 & 0 & 1 & 1 \\
\underline{1} & \underline{0} & \underline{0} & \underline{0} & \underline{0} & \underline{0} & 0 \\
\end{tabular}
Wiederholung nach 15 Iterationen.
Neuer IV: $1 1 1 1 1 1$
\begin{tabular}{|cccccc|c|}
$x_5$ & $x_4$ & $x_3$ & $x_2$ & $x_1$ & $x_0$ & Output \\\hline
1 & 1 & 1 & 1 & 1 & 1 & 1 \\
0 & 1 & 1 & 1 & 1 & 1 & 1 \\
0 & 0 & 1 & 1 & 1 & 1 & 1 \\
0 & 0 & 0 & 1 & 1 & 1 & 1 \\
1 & 0 & 0 & 0 & 1 & 1 & 1 \\
0 & 1 & 0 & 0 & 0 & 1 & 1 \\
1 & 0 & 1 & 0 & 0 & 0 & 0 \\
1 & 1 & 0 & 1 & 0 & 0 & 0 \\
1 & 1 & 1 & 0 & 1 & 0 & 0 \\
0 & 1 & 1 & 1 & 0 & 1 & 1 \\
1 & 0 & 1 & 1 & 1 & 0 & 0 \\
1 & 1 & 0 & 1 & 1 & 1 & 1 \\
1 & 1 & 1 & 0 & 1 & 1 & 1 \\
1 & 1 & 1 & 1 & 0 & 1 & 1 \\
1 & 1 & 1 & 1 & 1 & 0 & 0 \\
\underline{1} & \underline{1} & \underline{1} & \underline{1} & \underline{1} & \underline{1} & 1 \\
\end{tabular}
Wiederholung nach 15 Iterationen. $63 - 15 - 15 = 33$ Fehlende Zust<73>nde.
Neuer IV: $1 1 0 0 0 0$
\begin{tabular}{|cccccc|c|}
$x_5$ & $x_4$ & $x_3$ & $x_2$ & $x_1$ & $x_0$ & Output \\\hline
1 & 1 & 0 & 0 & 0 & 0 & 0 \\
0 & 1 & 1 & 0 & 0 & 0 & 0 \\
1 & 0 & 1 & 1 & 0 & 0 & 0 \\
0 & 1 & 0 & 1 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 1 & 1 \\
1 & 0 & 0 & 1 & 0 & 1 & 1 \\
0 & 1 & 0 & 0 & 1 & 0 & 0 \\
1 & 0 & 1 & 0 & 0 & 1 & 1 \\
0 & 1 & 0 & 1 & 0 & 0 & 0 \\
1 & 0 & 1 & 0 & 1 & 0 & 0 \\
0 & 1 & 0 & 1 & 0 & 1 & 1 \\
0 & 0 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 1 & 1 \\
0 & 0 & 0 & 0 & 1 & 0 & 0 \\
1 & 0 & 0 & 0 & 0 & 1 & 1 \\
\underline{1} & \underline{1} & \underline{0} & \underline{0} & \underline{0} & \underline{0} & 0 \\
\end{tabular}
Wiederholung nach 15 Iterationen. $63 - 15 - 15 - 15 = 18$ Fehlende Zust<73>nde.
Neuer IV: $1 1 1 0 0 0$
\begin{tabular}{|cccccc|c|}
$x_5$ & $x_4$ & $x_3$ & $x_2$ & $x_1$ & $x_0$ & Output \\\hline
1 & 1 & 1 & 0 & 0 & 0 & 0 \\
1 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 1 & 1 & 1 & 1 & 0 & 0 \\
1 & 0 & 1 & 1 & 1 & 1 & 1 \\
0 & 1 & 0 & 1 & 1 & 1 & 1 \\
1 & 0 & 1 & 0 & 1 & 1 & 1 \\
1 & 1 & 0 & 1 & 0 & 1 & 1 \\
0 & 1 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 1 & 1 & 0 & 1 & 1 \\
1 & 0 & 0 & 1 & 1 & 0 & 0 \\
0 & 1 & 0 & 0 & 1 & 1 & 1 \\
0 & 0 & 1 & 0 & 0 & 1 & 1 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 \\
1 & 0 & 0 & 0 & 1 & 0 & 0 \\
1 & 1 & 0 & 0 & 0 & 1 & 1 \\
\underline{1} & \underline{1} & \underline{1} & \underline{0} & \underline{0} & \underline{0} & 0 \\
\end{tabular}
Wiederholung nach 15 Iterationen. $63 - 15 - 15 - 15 - 15 = 3$ Fehlende Zust<73>nde.
Letzter IV: $1 0 1 1 0 1$
\begin{tabular}{|cccccc|c|}
$x_5$ & $x_4$ & $x_3$ & $x_2$ & $x_1$ & $x_0$ & Output \\\hline
1 & 0 & 1 & 1 & 0 & 1 & 1 \\
1 & 1 & 0 & 1 & 1 & 0 & 0 \\
0 & 1 & 1 & 0 & 1 & 1 & 1 \\
\underline{1} & \underline{0} & \underline{1} & \underline{1} & \underline{0} & \underline{1} & 1 \\
\end{tabular}
Wiederholung nach 3 Iterathonen. $63 - 15 - 15 - 15 - 15 -3 = 0$ fehlende Zust<73>nde.
Keine Sequenz maximaler L<>nge und L<>nge ist abh<62>ngig von IV $\Rightarrow$ reduzibles Polynom liegt zugrunde.
\end{enumerate} %}}}
\section*{Aufgabe 2}
\begin{eqnarray*}
s = 155 \text{ Mbits/sec} = 155 * 2^{20} \text{ bit/sec} \\
12h = 12 * 60 * 60 sec = 43200 sec \\
155 * 2^{20} \frac{bit}{sec} * 43200 sec = 7021264896000 bit
\end{eqnarray*}
Gesucht $m \in \mathbb{N}$, so dass $2^m - 1 > 7021264896000$ (gel<65>st mit Wolframalpha)
\begin{eqnarray*}
2^m - 1 &> 7021264896000 \\
m &> 42
\end{eqnarray*}
Vorausgesetzt, es handelt sich um ein primitives Polynom, ist der minimale Grad, der ben<65>tigt wird, dass eine
Wiederholung in der Schl<68>sselfolge fr<66>hestens nach 12 Stunden passiert $m = 43$.
\section*{Aufgabe 3}
\begin{enumerate}[a)]
\item $m = 8 \Rightarrow 2^m - 1 = 2^8 - 1 = 255$
\item $2*m - 1 = 2 * 8 - 1 = 15$
\item
\begin{align*}
y_i &\equiv x_i + s_i &\mod 2 \\
s_i &\equiv y_i + x_i &\mod 2
\end{align*}
Rekonstruieren der ersten 15 Bit des Schl<68>sselstroms mit Hilfe des known-plaintext \enquote{Mo} $\Rightarrow$
0x4d, 0x6f $\Rightarrow (01001101)_2, (01101111)_2$
Die ersten 2 Bytes des Ciphertext sind 0xEC, 0xD4 $\Rightarrow (11101100)_2, (11010100)_2$
Mit Hilfe des angeh<65>ngten Programms wurden die folgenden 2 Schl<68>sselstrom Bytes berechnet: $(10100001)_2,
(10111011)_2 \Rightarrow (A1)_{16}, (BB)_{16}$
\item Folgendes System $(A\mid b)$ gilt es zu l<>sen:
Die Matrix wurde mit Hilfe von \url{https://planetcalc.com/3324/} invertiert.
\begin{align*}
\begin{array}({@{}cccccccc|c@{}})
1 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 1 \\
1 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\
0 & 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 \\
1 & 0 & 1 & 1 & 0 & 0 & 0 & 0 & 1 \\
1 & 1 & 0 & 1 & 1 & 0 & 0 & 0 & 1 \\
1 & 1 & 1 & 0 & 1 & 1 & 0 & 0 & 0 \\
0 & 1 & 1 & 1 & 0 & 1 & 1 & 0 & 1 \\
1 & 0 & 1 & 1 & 1 & 0 & 1 & 1 & 1
\end{array} \\
Ax = b \Rightarrow A^{-1}b = x \\
A^{-1} =
\begin{matrix}
0 & 1 & 0 & 0 & 1 & 1 & 1 & 0 \\
0 & 0 & 1 & 0 & 0 & 1 & 1 & 1 \\
1 & 0 & 0 & 1 & 1 & 0 & 1 & 1 \\
1 & 1 & 0 & 0 & 0 & 1 & 0 & 1 \\
1 & 0 & 1 & 0 & 0 & 1 & 0 & 0 \\
0 & 1 & 0 & 1 & 0 & 0 & 1 & 0 \\
0 & 0 & 1 & 0 & 1 & 0 & 0 & 1 \\
1 & 0 & 0 & 1 & 1 & 1 & 0 & 0
\end{matrix} \\
b =
\begin{matrix}
1\\
0\\
1\\
1\\
1\\
0\\
1\\
1\\
\end{matrix}\\
x =
\begin{array}({@{}cccccccc@{}})
0 & 1 & 1 & 0 & 0 & 0 & 1 & 1
\end{array} \\
p_0 = 1 \\
p_1 = 1 \\
p_2 = 0 \\
p_3 = 0 \\
p_4 = 0 \\
p_5 = 1 \\
p_6 = 1 \\
p_7 = 0 \\
\end{align*}
\item Der Klartext ist \enquote{Mondl4ndunG}.
Berechnet mit dem Code im Anhang.
\item Die erste unsanfte und unbemannte Mondlandung war am 13.09.1959 (Lunik 2).
Die erste sanfte und unbemannte Mondlandung am 03.02.1966 (Luna 9)
Die erste bemannte Mondlandung war am 21.07.1969 (Apollo 11).
(Quelle: \url{https://de.wikipedia.org/wiki/Mondlandung})
\end{enumerate}
% \section*{Code}
% \inputminted{rust}{./school/intro-crypto/uebung/04/lfsr/src/main.rs}
\end{document}

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 648 KiB

View File

@ -0,0 +1,4 @@
[[package]]
name = "lfsr"
version = "0.1.0"

View File

@ -0,0 +1,6 @@
[package]
name = "lfsr"
version = "0.1.0"
authors = ["Valentin Brandl <vbrandl@riseup.net>"]
[dependencies]

View File

@ -0,0 +1,177 @@
struct Lfsr {
reg: Vec<bool>,
p: Vec<bool>,
}
impl Lfsr {
fn new(iv: &[bool], p: &[bool]) -> Self {
assert_eq!(iv.len(), p.len());
Self {
reg: iv.iter().cloned().collect(),
p: p.iter().cloned().collect(),
}
}
fn next(&mut self) -> bool {
// let res = self.reg[self.len - 1];
let next = self
.reg
.iter()
.zip(self.p.iter())
.map(|(n, m)| n & m)
.fold(false, |acc, v| acc ^ v);
self.reg.insert(0, next);
let ret = self.reg.pop().unwrap();
assert_eq!(self.reg.len(), self.p.len());
ret
}
fn state(&self) -> &[bool] {
&self.reg
}
}
fn convert_state(s: &[bool]) -> String {
s.iter()
.map(|x| if *x { "1".to_string() } else { "0".to_string() })
.collect::<Vec<String>>()
.join(" & ")
}
/// helper for 3c)
fn recover_keystream(plain: &[bool], cipher: &[bool]) -> Vec<bool> {
assert_eq!(plain.len(), cipher.len());
plain
.iter()
.zip(cipher.iter())
.map(|(a, b)| a ^ b)
.collect()
}
fn decrypt(l: &mut Lfsr, c: &[bool]) -> u8 {
let s: String = c
.into_iter()
.map(|c| c ^ l.next())
.map(|c| if c { "1" } else { "0" })
.collect();
u8::from_str_radix(&s, 2).unwrap()
}
/// main for 3d)
fn main() {
let p = &[false, true, true, false, false, false, true, true];
// let s = &[true, false, true, true, true, false, true, true];
// let s = &[true, false, true, false, false, false, false, true];
// let s = &[true, false, false, false, false, true, false, true];
let s = &[true, true, false, true, true, true, false, true];
let mut l = Lfsr::new(s, p);
// for _ in 0..17 {
// println!("{}", if lfsr.next() { "1" } else { "0" });
// }
// 00010011
// 11010100
let c = &[true, true, false, true, false, true, false, false];
let d = decrypt(&mut l, c);
println!("{}: {}", d, d as char);
// 00010011 = 0x13
let c = &[false, false, false, true, false, false, true, true];
let d = decrypt(&mut l, c);
println!("{}: {}", d, d as char);
// 00010000 = 0x10
let c = &[false, false, false, true, false, false, false, false];
let d = decrypt(&mut l, c);
println!("{}: {}", d, d as char);
// 01110101 = 0x75
let c = &[false, true, true, true, false, true, false, true];
let d = decrypt(&mut l, c);
println!("{}: {}", d, d as char);
// 01100000 = 0x60
let c = &[false, true, true, false, false, false, false, false];
let d = decrypt(&mut l, c);
println!("{}: {}", d, d as char);
// 00000101 = 0x05
let c = &[false, false, false, false, false, true, false, true];
let d = decrypt(&mut l, c);
println!("{}: {}", d, d as char);
// 01111100 = 0x7c
let c = &[false, true, true, true, true, true, false, false];
let d = decrypt(&mut l, c);
println!("{}: {}", d, d as char);
// 01010000 = 0x50
let c = &[false, true, false, true, false, false, false, false];
let d = decrypt(&mut l, c);
println!("{}: {}", d, d as char);
// 11011011 = 0xdb
let c = &[true, true, false, true, true, false, true, true];
let d = decrypt(&mut l, c);
println!("{}: {}", d, d as char);
// 01110011 = 0x73
let c = &[false, true, true, true, false, false, true, true];
let d = decrypt(&mut l, c);
println!("{}: {}", d, d as char);
}
// fn main() {
// let plain = &[
// false, true, false, false, true, true, false, true, false, true, true, false, true, true,
// true, true,
// ];
// let cipher = &[
// true, true, true, false, true, true, false, false, true, true, false, true, false, true,
// false, false,
// ];
// let key_stream = recover_keystream(plain, cipher);
// println!(
// "{}",
// key_stream
// .iter()
// .map(|k| if *k { "1, " } else { "0, " })
// .collect::<String>()
// );
// }
/// main for exercise 1
fn main1() {
// 1a)
// let mut lfsr = Lfsr::new(
// &[true, true, false, false, false, false],
// // &[true, true, true, true, true, true],
// // &[true, false, false, false, false, false],
// &[false, true, false, true, true, true],
// );
// 1b)
// let mut lfsr = Lfsr::new(
// // &[true, true, true, true, true, true],
// &[true, false, false, false, false, false],
// &[false, false, false, false, true, true],
// );
// 1c)
let mut lfsr = Lfsr::new(
// &[true, true, true, false, false, false],
// &[true, true, false, false, false, false],
&[true, false, true, true, false, true],
// &[true, true, true, true, true, true],
// &[true, false, false, false, false, false],
&[false, false, true, true, true, true],
);
let mut seen = Vec::new();
let mut i = 0;
while !seen.contains(&lfsr.state().iter().cloned().collect::<Vec<_>>()) {
seen.push(lfsr.state().iter().cloned().collect::<Vec<_>>());
print!("{}", convert_state(lfsr.state()));
println!(" & {} \\\\", if lfsr.next() { 1 } else { 0 });
i += 1;
}
eprintln!("Repetition after {} iterations", i);
}

View File

@ -0,0 +1 @@
{"rustc_fingerprint":6445661432976150582,"outputs":{"1164083562126845933":["rustc 1.30.0 (da5f414c2 2018-10-24)\nbinary: rustc\ncommit-hash: da5f414c2c0bfe5198934493f04c676e2b23ff2e\ncommit-date: 2018-10-24\nhost: x86_64-unknown-linux-gnu\nrelease: 1.30.0\nLLVM version: 8.0\n",""],"15337506775154344876":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\nunix\n",""],"1617349019360157463":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/me/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\nunix\n",""]},"successes":{}}

View File

@ -0,0 +1 @@
{"rustc":7311099760834594431,"features":"[]","target":12005888738967920787,"profile":690535219432825423,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1542232988,806345654],".fingerprint/lfsr-19130ef987a3303b/dep-bin-lfsr-19130ef987a3303b"]}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":7311099760834594431,"features":"[]","target":12005888738967920787,"profile":8064701370884557241,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1542232985,983443064],".fingerprint/lfsr-c5c66887bdea01a0/dep-bin-lfsr-c5c66887bdea01a0"]}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1,5 @@
/home/me/Dokumente/notes/school/intro-crypto/uebung/04/lfsr/target/debug/deps/lfsr-19130ef987a3303b: src/main.rs
/home/me/Dokumente/notes/school/intro-crypto/uebung/04/lfsr/target/debug/deps/lfsr-19130ef987a3303b.d: src/main.rs
src/main.rs:

View File

@ -0,0 +1,5 @@
/home/me/Dokumente/notes/school/intro-crypto/uebung/04/lfsr/target/debug/deps/lfsr-c5c66887bdea01a0.rmeta: src/main.rs
/home/me/Dokumente/notes/school/intro-crypto/uebung/04/lfsr/target/debug/deps/lfsr-c5c66887bdea01a0.d: src/main.rs
src/main.rs:

Binary file not shown.

View File

@ -0,0 +1 @@
/home/me/Dokumente/notes/school/intro-crypto/uebung/04/lfsr/target/debug/lfsr: /home/me/Dokumente/notes/school/intro-crypto/uebung/04/lfsr/src/main.rs

View File

@ -0,0 +1 @@
/home/me/Dokumente/notes/school/intro-crypto/uebung/04/lfsr/target/debug/liblfsr.rmeta: /home/me/Dokumente/notes/school/intro-crypto/uebung/04/lfsr/src/main.rs

Binary file not shown.

Binary file not shown.