Add crypto exercise
All checks were successful
the build was successful

This commit is contained in:
Valentin Brandl 2018-11-27 22:28:37 +01:00
parent 7d9dd66f1a
commit ff5bbc1a8a
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D
51 changed files with 364 additions and 0 deletions

View File

@ -0,0 +1,252 @@
\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 {5} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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}}%
\newcommand{\csquare}{\text{\rlap{$\checkmark$}}\square}%
\begin{document}
%Import header
\hwsol
\section*{Aufgabe 1}
\begin{enumerate}[a)]
\item Das National Bureau of Standards (NBS) (heute National Institute of Standards and Technology (NIST)) hat die
Entwicklung des DES ausgeschrieben.
\item DES wurde 1977 standardisiert.
\item Die National Security Agency (NSA) hat an der Entwicklung des DES mitgewirkt.
\item Die Kryptographen, die den Kandidaten eingereicht haben, gehörten IBM an.
\item Auf einen Feistel Netz mit einer Blockgröße von 64 bit und einer Schlüssellänge von 128 bit
\item Die Schlüssellänge von Lucifer ist 128 bit
\item Die Schlüssellänge des DES ist 56 bit und das Sicherheitsniveau ist 56 bit.
\item Es werden 64 bit in einer DES Operation verschlüsselt.
\item Abbildung \ref{feist_alg} und \ref{feist_round}
\begin{figure}[h!]
\centering
\includegraphics[scale=0.5]{./build/school/intro-crypto/uebung/05/a1i.png}
\caption{Allgemeine Struktur eines Feistel Netzes}
\label{feist_alg}
\end{figure}
\begin{figure}[h!]
\centering
\includegraphics[width=\textwidth]{school/intro-crypto/uebung/05/a1i2.jpg}
\caption{Struktur einer Feistel Runde}
\label{feist_round}
\end{figure}
\end{enumerate}
\section*{Aufgabe 2}
\begin{enumerate}[a)]
\item
\begin{tabular}{|c|ccccc|}
\hline
$S_4$ & 0 & 1 & 2 & 3 & 4 \\\hline
0 & 07 & 13 & 14 & 03 & 00 \\\hline
1 & 13 & 08 & 11 & 05 & 06 \\\hline
\end{tabular}
\begin{tabular}{|c|ccccc|}
\hline
& 0 & 1 & 2 & 3 & 4 \\\hline
$(y_1,y_2,y_3,y_4)$ & 0111 & 1101 & 1110 & 0011 & 0000 \\\hline
$(y_2,y_1,y_4,y_3)$ & 1011 & 1110 & 1101 & 0011 & 0000 \\\hline
$(y_2,y_1,y_4,y_3) \oplus (0,1,1,0)$ & 1101 & 1000 & 1011 & 0101 & 0110 \\\hline
Dezimal & 13 & 8 & 11 & 5 & 6 \\\hline
\end{tabular}
Das Ergebnis entspricht genau der 1. Zeile in der S-Box $S_4$.
\item
\begin{tabular}{|c|ccccc|}
\hline
$S_4$ & 0 & 1 & 2 & 3 & 4 \\\hline
2 & 10 & 06 & 09 & 00 & 12 \\\hline
3 & 03 & 15 & 00 & 06 & 10 \\\hline
\end{tabular}
Tabelle in binär:
\begin{tabular}{|c|ccccc|}
\hline
$S_4$ & 0 & 1 & 2 & 3 & 4 \\\hline
2 & 1010 & 0110 & 1001 & 0000 & 1100 \\\hline
3 & 0011 & 1111 & 0000 & 0110 & 1010 \\\hline
\end{tabular}
Gesucht:
\begin{itemize}
\item Permutationsfunktion $f : (y_1,y_2,y_3,y_4) \to (y_1',y_2',y_3',y_4')$
\item xor Parameter $x = (x_1,x_2,x_3,x_4)$
\end{itemize}
Der Ausgangswert von Spalte 3 (0000) bleibt von der Permutationsfunktion unverändert: $f(0000) = 0000 \Rightarrow x
= 0000 \oplus 0110 = 0110$
\begin{tabular}{|c|ccccc|}
\hline
$S_4$ & 0 & 1 & 2 & 3 & 4 \\\hline
3 & 0011 & 1111 & 0000 & 0110 & 1010 \\\hline
Zeile $3 \oplus 0110$ & 0101 & 1001 & 0110 & 0000 & 1100 \\\hline
2 & 1010 & 0110 & 1001 & 0000 & 1100 \\\hline
\end{tabular}
Man kann sehen, dass wieder $y_1$ mit $y_2$ und $y_3$ mit $y_4$ vertauscht werden.
$\Rightarrow$ Ableitung von Zeile 2 zu 3:
\begin{align*}
(y_1,y_2,y_3,y_4) \to (y_2,y_1,y_4,y_3) \oplus (0,1,1,0)
\end{align*}
\end{enumerate}
\section*{Aufgabe 3}
\begin{tabular}{|c|ccccccccc|}
\hline
& $x_1$ & $x_2$ & ... & $x_{56}$ & $x_{57}$ & $x_{58}$ & ... & $x_{63}$ & $x_{64}$ \\\hline
Eingabe $x$ & 1 & 1 & ... & 1 & 0 & 1 & ... & 1 & 1 \\\hline
$IP(x)$ & 1 & 1 & ... & 1 & 1 & 1 & ... & 0 & 1 \\\hline
\end{tabular}
$L_0 = 11111111111111111111111111111111$
$R_0 = 11111111111111111111111111111101 = L_1$
Das zu beobachtende Bit steht an Position $31$.
$E(R_0) = 111111111111111111111111111111111111111111111011$
\begin{enumerate}[a)]
\item Auswirkungen:
$S_1\ \square$
$S_2\ \square$
$S_3\ \square$
$S_4\ \square$
$S_5\ \square$
$S_6\ \square$
$S_7\ \square$
$S_8\ \csquare$
Eingangsbits: $E(R_0) \oplus 111111111111111111111111111111111111111111111111$
S-Box $S_1$: $000000$
S-Box $S_2$: $000000$
S-Box $S_3$: $000000$
S-Box $S_4$: $000000$
S-Box $S_5$: $000000$
S-Box $S_6$: $000000$
S-Box $S_7$: $000000$
S-Box $S_8$: $000100$
\item
Ausgabe der S-Boxen:
S-Box $S_1$: $14 = 1110$
S-Box $S_2$: $15 = 1111$
S-Box $S_3$: $10 = 1010$
S-Box $S_4$: $07 = 0111$
S-Box $S_5$: $02 = 0010$
S-Box $S_6$: $12 = 1100$
S-Box $S_7$: $04 = 0100$
S-Box $S_8$: $08 = 1000$
Ausgabe nach allen S-Boxen: $s = 11101111101001110010110001001000$
$P(s) = 10000010010110011101011100111011$ (berechnet mit Code im Anhang)
$P(s) \oplus L_0 = 01111101101001100010100011000100 = R_1$
\begin{align*}
L_1 = R_0:\\
11111111111111111111111111111101 \\
R_1:\\
01111101101001100010100011000100
\end{align*}
\item
\begin{align*}
L_1:\\
R_1:\\
\end{align*}
\end{enumerate}
\section*{Aufgabe 4}
\end{document}

View File

@ -0,0 +1,46 @@
digraph {
{
rank=same;
0 [ style="invisible" shape="point" width=0 ];
3 [ style="invisible" shape="point" width=0 ];
}
{
rank=same;
1 [ style="invisible" shape="point" width=0 ];
4 [ style="invisible" shape="point" width=0 ];
}
{
rank=same;
2 [ style="invisible" shape="point" width=0 ];
5 [ style="invisible" shape="point" width=0 ];
}
{
rank=same;
r1 [ label="Runde 1" shape="box" ];
s1 [ label="" shape="box" ];
}
{
rank=same;
rn [ label="Runde n" shape="box" ];
sn [ label="" shape="box" ];
}
3 -> s1 [ label="K" ];
s1 -> r1 [ label="K1" ];
s1 -> 4;
4 -> sn [ style="dotted" ];
sn -> rn [ label="Kn" ];
0 -> r1 [ label="x" ];
r1 -> 1;
1 -> rn [ style="dotted" ];
rn -> 2 [ label="y" ];
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

View File

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

View File

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

View File

@ -0,0 +1,39 @@
const P: [usize; 32] = [
16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10, 2, 8, 24, 14, 32, 27, 3, 9, 19,
13, 30, 6, 22, 11, 4, 25,
];
fn p<T: Copy + Default>(i: [T; 32]) -> [T; 32] {
let mut res: [T; 32] = [T::default(); 32];
for (i, p) in i.iter().zip(P.iter()) {
res[*p - 1] = *i;
}
res
}
fn main() {
let i: [u8; 32] = [
1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0,
0, 0,
];
p(i).iter().for_each(|i| print!("{}", i));
println!();
let p = &[
true, false, false, false, false, false, true, false, false, true, false, true, true,
false, false, true, true, true, false, true, false, true, true, true, false, false, true,
true, true, false, true, true,
];
let l0 = &[
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true, true,
];
p.iter()
.zip(l0.iter())
.map(|(a, b)| a ^ b)
.map(|x| if x { '1' } else { '0' })
.for_each(|x| print!("{}", x));
println!();
}

View File

@ -0,0 +1 @@
{"rustc_fingerprint":1996615077234892980,"outputs":{"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",""],"1164083562126845933":["rustc 1.30.1 (1433507eb 2018-11-07)\nbinary: rustc\ncommit-hash: 1433507eba7d1a114e4c6f27ae0e1a74f60f20de\ncommit-date: 2018-11-07\nhost: x86_64-unknown-linux-gnu\nrelease: 1.30.1\nLLVM version: 8.0\n",""]},"successes":{}}

View File

@ -0,0 +1 @@
{"rustc":3409524444662720818,"features":"[]","target":6265867820755230167,"profile":8404152588981882898,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1543354048,10023042],".fingerprint/p-317830ef682f5c46/dep-bin-p-317830ef682f5c46"]}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":3409524444662720818,"features":"[]","target":6265867820755230167,"profile":256579555595379356,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1543354051,669476378],".fingerprint/p-a8d68fe4b06c3a8a/dep-bin-p-a8d68fe4b06c3a8a"]}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1,5 @@
/home/me/Dokumente/notes/school/intro-crypto/uebung/05/p/target/debug/deps/p-317830ef682f5c46.rmeta: src/main.rs
/home/me/Dokumente/notes/school/intro-crypto/uebung/05/p/target/debug/deps/p-317830ef682f5c46.d: src/main.rs
src/main.rs:

View File

@ -0,0 +1,5 @@
/home/me/Dokumente/notes/school/intro-crypto/uebung/05/p/target/debug/deps/p-a8d68fe4b06c3a8a: src/main.rs
/home/me/Dokumente/notes/school/intro-crypto/uebung/05/p/target/debug/deps/p-a8d68fe4b06c3a8a.d: src/main.rs
src/main.rs:

View File

@ -0,0 +1 @@
/home/me/Dokumente/notes/school/intro-crypto/uebung/05/p/target/debug/libp.rmeta: /home/me/Dokumente/notes/school/intro-crypto/uebung/05/p/src/main.rs

Binary file not shown.

View File

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

Binary file not shown.