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

This commit is contained in:
Valentin Brandl
2018-10-31 21:34:58 +01:00
parent 97f112131d
commit 3022f10fe7
49 changed files with 349 additions and 0 deletions

View File

@ -0,0 +1,221 @@
\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{csquotes}
\usepackage{graphicx}
\usepackage{epsfig}
\usepackage{paralist}
\geometry{left=2.0cm,textwidth=17cm,top=3.5cm,textheight=23cm}
%%%%%%%%%% 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 {1} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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}
Ciphertext:
\begin{align*}
\text{Hex} && \text{Bin} \\
(DC)_{16} &=& (11011100)_2 \\
(48)_{16} &=& (01001000)_2 \\
(13)_{16} &=& (00010011)_2
\end{align*}
Schl<EFBFBD>ssel:
\begin{align*}
\text{Hex} && \text{Bin} \\
(98)_{16} &=& (10011000)_2 \\
(29)_{16} &=& (00101001)_2 \\
(60)_{16} &=& (01100000)_2
\end{align*}
Bin<EFBFBD>re berechnung der ersten 3 Bytes:
\begin{itemize}
\item
\begin{tabular}{ccccccccc}
& 1 & 1 & 0 & 1 & 1 & 1 & 0 & 0 \\
xor & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 0 \\
\hline
& 0 & 1 & 0 & 0 & 0 & 1 & 0 & 0
\end{tabular}
$(01000100)_2 = (44)_{16} = `D`_{ASCII}$
\item
\begin{tabular}{ccccccccc}
& 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 \\
xor & 0 & 0 & 1 & 0 & 1 & 0 & 0 & 1 \\
\hline
& 0 & 1 & 1 & 0 & 0 & 0 & 0 & 1
\end{tabular}
$(01100001)_2 = (61)_{16} = `a`_{ASCII}$
\item
\begin{tabular}{ccccccccc}
& 0 & 0 & 0 & 1 & 0 & 0 & 1 & 1 \\
xor & 0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 \\
\hline
& 0 & 1 & 1 & 1 & 0 & 0 & 1 & 1
\end{tabular}
$(01110011)_2 = (73)_{16} = `s`_{ASCII}$
\end{itemize}
\begin{itemize}
\item
\begin{tabular}{lcccccccccccc}
Ciphertext & DC & 48 & 13 & 3B & 9C & 4C & 49 & 80 & AC & A7 & B9 & 54 \\
Schl<68>ssel & 98 & 29 & 60 & 72 & F2 & 38 & 2C & F2 & C2 & C2 & CD & 1D \\
\hline
Plaintext & 44 & 61 & 73 & 49 & 6E & 74 & 65 & 72 & 6E & 65 & 74 & 49 \\
ASCII & D & a & s & I & n & t & e & r & n & e & t & I
\end{tabular}
\item
\begin{tabular}{lcccccccccccc}
Ciphertext & F2 & 7C & 2B & 9E & D5 & DF & 0D & 05 & B3 & 1D & 4E & F8 \\
Schl<68>ssel & 81 & 08 & 65 & FB & A0 & B3 & 6C & 6B & D7 & 3C & 6F & D9 \\
\hline
Plaintext & 73 & 74 & 4E & 65 & 75 & 6C & 61 & 6E & 64 & 21 & 21 & 21 \\
ASCII & s & t & N & e & u & l & a & n & d & ! & ! & !
\end{tabular}
Plaintext: \enquote{DasInternetIstNeuland!!!}.
\end{itemize}
\section*{Aufgabe 2}
Da jedes Bit im Ciphertext ein eigenes Bit im Schl<68>ssel hat, l<>sst sich jeder beliebige Klartext (der selben L<>nge) aus
dem Ciphertext ableiten, zumindest wenn der Schl<68>ssel richtig gew<65>hlt wird. Daher ist es nicht m<>glich, zu sagen, ob ein
Schl<EFBFBD>ssel korrekt ist, ohne den urspr<70>nglichen Plaintext zu kennen.
\section*{Aufgabe 3}
\begin{enumerate}[(a)]
\item Die Magic Number des PNG Formats ist $89$ $50$ $4e$ $47$ $0d$ $0a$ $1a$ $0a$. Diese 8 Bytes bilden den Anfang
jeder validen PNG Datei. Das er<65>ffnet die M<>glichkeit f<>r einen Known-Plaintext Angriff.
\item F<>r $a$, $b$ und $c$ mit $a \text{ xor } b = c$ gilt $b \text{ xor } c = a$ und $a \text{ xor } c = b$, also
l<>sst sich der Schl<68>ssel berechnen, in dem man den Ciphertext mit dem Known-Plaintext xor'ed.
\begin{tabular}{lcccccccc}
Ciphertext (hex) & 33 & fd & eb & 12 & cd & 0a & 0a & f5 \\
Known Plaintext (hex) & 89 & 50 & 4e & 47 & 0d & 0a & 1a & 0a \\
\hline
Schl<68>ssel (hex) & ba & ad & a5 & 55 & c0 & 00 & 10 & ff \\
\end{tabular}
\item Die S<><53>igkeiten sind im Lageraum im ID (gegen<65>ber vom Fachschaftsraum), in dem Regal direkt gegen<65>ber der
T<>r. Ca auf der H<>he zwischen T<>re und Grill.
\end{enumerate}
\section*{Aufgabe 4}
\begin{enumerate}[(a)]
\item
\begin{enumerate}[1)]
\item Berechnung der ersten 8 Bytes des Schl<68>sselstroms:
Known Plaintext: \enquote{https://} $\Rightarrow$ $68$ $74$ $74$ $70$ $73$ $3a$ $2f$ $2f$
\begin{tabular}{lcccccccc}
Ciphertext & 4E & 7E & 3D & 88 & 8E & 01 & 0D & 84 \\
Known-Plaintext & 68 & 74 & 74 & 70 & 73 & 3A & 2F & 2F \\
\hline
Schl<68>ssel & 26 & 0A & 49 & F8 & FD & 3B & 22 & AB \\
\end{tabular}
\item Aufstellen eines Gleichungssystems zur Bestimmung von $A$, $B$ und $C$ des LCG:
$m = 257$
\begin{eqnarray*}
S_0 &= (26)_{16} = (38)_{10} \\
S_1 &= (0A)_{16} = (10)_{10} \\
S_2 &= (49)_{16} = (73)_{10} \\
S_3 &= (F8)_{16} = (248)_{10} \\
S_4 &= (FD)_{16} = (253)_{10} \\\\
S_2 &\equiv A * S_1 + B * S_0 + C &\mod 257 \\
S_3 &\equiv A * S_2 + B * S_1 + C &\mod 257 \\
S_4 &\equiv A * S_3 + B * S_2 + C &\mod 257 \\
\end{eqnarray*}
\begin{align}
73 &\equiv 10 * A + 38 * B + C &\mod 257 \\
C &\equiv 73 - 10 * A - 38 * B &\mod 257 \\
\\
248 &\equiv 73 * A + 10 * B + 73 - 10 * A - 38 * B &\mod 257 \\
248 &\equiv 63 * A - 28 * B + 73 &\mod 257 \\
63 * A &\equiv 175 + 28 * B &\mod 257 \\
A &\equiv 29 * B + 117 &\mod 257 \\
\\
253 &\equiv 248(29*B + 117) + 73 * B + 73 - 10(29*B + 117) - 38*B &\mod 257 \\
253 &\equiv 253*B + 232 + 73*B + 73 - 33*B - 142 - 38 *B &\mod 257 \\
253 &\equiv 255*B + 163 &\mod 257 \\
255*B &\equiv 90 &\mod 257 \\
\underline{B} &\equiv 212 &\mod 257 \\
\\
A &\equiv 29 * 212 + 117 &\mod 257 \\
\underline{A} &\equiv 97 &\mod 257 \\
\\
C &\equiv 73 - 10 * 97 - 38 * 212 &\mod 257 \\
\underline{C} &\equiv 42 &\mod 257
\end{align}
$A = 97 \mod 257$, $B = 212 \mod 257$, $C = 42 \mod 257$
Plaintext: \url{https://youtu.be/VmUGe8KDdGI}
\end{enumerate}
\item Es werden $n+1$ Parameter und $n$ Seed-Werte ben<65>tigt. Da man also $n+1$ Unbekannte im aufzustellenden
Gleichungssystem hat, werden auch $n+1$ Klartext-Chiffretext-Paare f<>r einen erfolgreichen Angriff ben<65>tigt.
\end{enumerate}
\end{document}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View File

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

View File

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

View File

@ -0,0 +1,101 @@
// use std::fs;
struct Prng {
a: u16,
b: u16,
c: u16,
s0: u16,
s1: u16,
}
impl Iterator for Prng {
type Item = u8;
fn next(&mut self) -> Option<u8> {
let r = self.s0;
self.s0 = self.s1;
self.s1 = ((self.a * self.s1) % 257 + (self.b * r) % 257 + self.c) % 257;
Some((r % 256) as u8)
}
}
impl Prng {
fn new(s0: u16, s1: u16) -> Self {
Self {
s0: s0 % 257,
s1: s1 % 257,
a: 97,
b: 212,
c: 42,
}
}
}
fn main() {
// let c: &[u8] = &[0x4E, 0x7E, 0x3D, 0x88, 0x8E, 0x01, 0x0D, 0x84];
// let p: &[u8] = &[0x68, 0x74, 0x74, 0x70, 0x73, 0x3A, 0x2F, 0x2F];
// c.iter()
// .zip(p.iter())
// .map(|(c, p)| c ^ p)
// .for_each(|k| print!("{:02X} ", k));
let c: &[u8] = &[
0x4E, 0x7E, 0x3D, 0x88, 0x8E, 0x01, 0x0D, 0x84, 0xB8, 0x7E, 0xBF, 0x1A, 0x25, 0x37, 0xFA,
0x4D, 0x89, 0x87, 0x91, 0xFA, 0x50, 0x51, 0xFC, 0x42, 0x7A, 0x9A, 0x6A, 0xE4,
];
let p = Prng::new(0x26, 0x0a);
c.into_iter()
.zip(p)
.map(|(c, k)| c ^ k)
.map(|c| c as char)
.for_each(|c| print!("{}", c));
println!();
// let key: &[u8] = &[0xba, 0xad, 0xa5, 0x55, 0xc0, 0x00, 0x10, 0xff];
// // let cipher: &[u8] = &[0x33, 0xfd, 0xeb, 0x12, 0xcd, 0x0a, 0x0a, 0xf5];
// // let key: &[u8] = &[0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
// // cipher
// // .iter()
// // .zip(key.iter())
// // .map(|(c, k)| c ^ k)
// // .for_each(|p| print!("0x{:x} ", p));
// let args: Vec<_> = std::env::args().skip(1).collect();
// let data = fs::read(&args[0]).expect("Cannot read");
// let plain: Vec<_> = data
// .into_iter()
// .zip(key.into_iter().cycle())
// .map(|(c, k)| c ^ k)
// .collect();
// fs::write(&args[1], plain).expect("Cannot write");
}
// fn main() {
// let cipher: &[u8] = &[
// 0xDC, 0x48, 0x13, 0x3B, 0x9C, 0x4C, 0x49, 0x80, 0xAC, 0xA7, 0xB9, 0x54, 0xF2, 0x7C, 0x2B,
// 0x9E, 0xD5, 0xDF, 0x0D, 0x05, 0xB3, 0x1D, 0x4E, 0xF8,
// ];
// let key: &[u8] = &[
// 0x98, 0x29, 0x60, 0x72, 0xF2, 0x38, 0x2C, 0xF2, 0xC2, 0xC2, 0xCD, 0x1D, 0x81, 0x08, 0x65,
// 0xFB, 0xA0, 0xB3, 0x6C, 0x6B, 0xD7, 0x3C, 0x6F, 0xD9,
// ];
// cipher.iter().for_each(|c| print!("0x{:X} ", c));
// println!();
// key.iter().for_each(|c| print!("0x{:X} ", c));
// println!();
// cipher
// .iter()
// .zip(key.iter())
// .map(|(c, k)| c ^ k)
// .for_each(|p| print!("{:X} ", p));
// println!();
// cipher
// .iter()
// .zip(key.iter())
// .map(|(c, k)| c ^ k)
// .map(|c| c as char)
// .for_each(|p| print!("{} ", p));
// println!();
// }

View File

@ -0,0 +1 @@
{"rustc_fingerprint":12819272735836075344,"outputs":{"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",""],"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",""],"1164083562126845933":["rustc 1.29.2 (17a9dc751 2018-10-05)\nbinary: rustc\ncommit-hash: 17a9dc7513b9fea883dc9505f09f97c63d1d601b\ncommit-date: 2018-10-05\nhost: x86_64-unknown-linux-gnu\nrelease: 1.29.2\nLLVM version: 7.0\n",""]}}

View File

@ -0,0 +1 @@
{"rustc":2049182171942789226,"features":"[]","target":8092603168892422263,"profile":7338771462028609488,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1541015098,863087767],".fingerprint/u03-4d5f92818f15e465/dep-bin-u03-4d5f92818f15e465"]}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1 @@
{"rustc":2049182171942789226,"features":"[]","target":8092603168892422263,"profile":8925656243208791261,"path":1036222786711178230,"deps":[],"local":[{"MtimeBased":[[1541015093,869731229],".fingerprint/u03-560dcfd44619ed7e/dep-bin-u03-560dcfd44619ed7e"]}],"rustflags":[],"edition":"Edition2015"}

View File

@ -0,0 +1,5 @@
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/deps/u03-4d5f92818f15e465: src/main.rs
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/deps/u03-4d5f92818f15e465.d: src/main.rs
src/main.rs:

View File

@ -0,0 +1,5 @@
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/deps/u03-560dcfd44619ed7e.rmeta: src/main.rs
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/deps/u03-560dcfd44619ed7e.d: src/main.rs
src/main.rs:

View File

@ -0,0 +1 @@
/home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/target/debug/libu03.rmeta: /home/me/Dokumente/notes/school/intro-crypto/uebung/03/u03/src/main.rs

Binary file not shown.

View File

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