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

weitere Beispiel-Programme und Musterlösung 8.10.2018, Praktikumsunterlagen Versuch 1

parent d82a95d6
No related branches found
No related tags found
No related merge requests found
Showing with 367 additions and 1 deletion
#include <stdio.h>
int main (void)
{
int a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%d", &a);
a = 2 * a;
printf ("Das Doppelte ist: %d\n", a);
return 0;
}
#include <stdio.h>
int main (void)
{
double a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%d", &a);
a = 2 * a;
printf ("Das Doppelte ist: %lf\n", a);
return 0;
}
#include <stdio.h>
int main (void)
{
double a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%d", &a);
a = 2 * a;
printf ("Das Doppelte ist: %d\n", a);
return 0;
}
#include <stdio.h>
int main (void)
{
int a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%lf", &a);
a = 2 * a;
printf ("Das Doppelte ist: %lf\n", a);
return 0;
}
#include <stdio.h>
int main (void)
{
long long int a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%lf", &a);
a = 2 * a;
printf ("Das Doppelte ist: %lf\n", a);
return 0;
}
.file "hello-1.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "Hello, world!"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc #include <stdio.h>
subq $8, %rsp
.cfi_def_cfa_offset 16 int main (void)
leaq .LC0(%rip), %rdi {
call puts@PLT printf ("Hello, world!\n");
movl $0, %eax return 0;
addq $8, %rsp }
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE11:
.size main, .-main
.ident "GCC: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516"
.section .note.GNU-stack,"",@progbits
#include <stdio.h>
int main (void)
{
puts ("Hello, world!");
return 0;
}
.file "hello-2.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "Hello, world!"
.text
.globl main
.type main, @function
main:
.LFB11:
.cfi_startproc
subq $8, %rsp
.cfi_def_cfa_offset 16
leaq .LC0(%rip), %rdi
call puts@PLT
movl $0, %eax
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE11:
.size main, .-main
.ident "GCC: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516"
.section .note.GNU-stack,"",@progbits
No preview for this file type
......@@ -749,7 +749,7 @@
\color{red}
sehr fragwürdig\\[\smallskipamount]
\footnotesize(siehe z.\,B.:\\
http://xkcd.com/292/
http://xkcd.com/292/)
\end{minipage}}
\end{picture}
\end{onlyenv}
......
File added
% hp-2018ws-p1.pdf - Labor Notes on Low-Level Programming
% Copyright (C) 2014, 2015, 2016, 2017, 2018 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: Versuch 1, 10., 17. und 24.10.2018: RSA-Verschlüsselung
\documentclass[a4paper]{article}
\usepackage{pgscript}
\usepackage{multicol}
\usepackage{sfmath}
\sloppy
\pagestyle{empty}
\newcommand{\sep}{~$\cdot$~}
\newcommand{\mylicense}{CC-by-sa (Version 3.0) oder GNU GPL (Version 3 oder höher)}
\begin{document}
\makebox(0,0.005)[tl]{\includegraphics[scale=0.72]{logo-hochschule-bochum-cvh-text-v2.pdf}}\hfill
\makebox(0,0)[tr]{\includegraphics[scale=0.5]{logo-hochschule-bochum.pdf}}
\par\bigskip\bigskip
\begin{center}
\Large\textbf{Praktikumsversuch 1: RSA-Verschlüsselung}
\par\medskip
\normalsize Hardwarenahe Programmierung / Angewandte Informatik\\
Wintersemester 2018/19\sep
Prof.~Dr.~Peter Gerwinski
\end{center}
Aufgabe: Schreiben Sie ein Programm, das
die Verschlüsselung nach Rivest, Shamir und Adleman (RSA)
sowie die Schwierigkeiten beim Brechen ("`Knacken"') der
Verschlüsselung demonstriert.
\begin{multicols}{2}
Schreiben Sie ein C-Programm (oder mehrere),
das folgendes durchführt:
\begin{itemize}
\item
\textbf{Schlüsselerzeugung}
Bestimmen Sie 3 Primzahlen $p$, $q$ und $e$, wobei $e$
kleiner als $(p-1)\cdot(q-1)$ und teilerfremd zu $(p-1)\cdot(q-1)$ sei.
(Dies ist z.\,B.\ der Fall, wenn $e$ größer als $p$ und $q$ ist.)
Berechnen Sie $N = p \cdot q$
sowie eine natürliche Zahl $d$ mit der Eigenschaft:
\begin{displaymath}
(e \cdot d) \,\%\, \bigl((p-1)\cdot(q-1)\bigr) = 1
\end{displaymath}
("`$x \,\%\, y\/$"' wird "`x modulo y"' gesprochen und steht
für den Rest, der bei Division von $x$ durch $y$ verbleibt.
$N$ und $e$ sind der \newterm{öffentliche Schlüssel}. \\
$p$, $q$ und $d$ sind der \newterm{geheime Schlüssel}.
\item
\textbf{Verschlüsselung}
Wählen Sie eine geheime Botschaft $m$ (eine Zahl),
die Sie verschlüsseln wollen.
$m$ muß teilerfremd zu $N$ sein.
(Dies ist z.\,B.\ der Fall, wenn $m$ kleiner ist als $N$
und es nicht gleich $p$ oder gleich $q$ ist.)
Schreiben Sie ein Programm, das aus $m$ die verschlüsselte
Nachricht $c$ berechnet:
\begin{displaymath}
c = m^e ~\%\, N
\end{displaymath}
\strut\vfill\goodbreak
Hinweis:
\begin{displaymath}
m^e ~\%\, N
= \underbrace{(m \cdot m \cdot \dots \cdot m)}_{\mbox{$e$ Faktoren}} \,\%\, N
\hspace*{2cm}
\end{displaymath}
\vspace*{-\medskipamount}
\begin{displaymath}
= \underbrace{\Bigl(\dots\bigl((m \cdot m) \,\%\, N \cdot m\bigr) \,\%\, N \cdot \dots \cdot m\Bigr) \,\%\, N}_{\mbox{$e$ Faktoren}}
\end{displaymath}
Dies bedeutet: Multiplizieren Sie die Zahl $m$ $e$-mal mit sich selbst,
wobei Sie \emph{nach jeder Multiplikation\/} modulo $N$ rechnen.
% \vfill\goodbreak
\item
\textbf{Entschlüsselung}
Rekonstruieren Sie aus der verschlüsselten Botschaft $c$
wieder die geheime Botschaft $m$:
\begin{displaymath}
m = c^d ~\%\, N
\end{displaymath}
\item
\textbf{Verschlüsselung brechen}
Rekonstruieren Sie aus der verschlüsselten Botschaft $c$
wieder die geheime Botschaft $m$,
\emph{ohne\/} den geheimen Schlüssel zu kennen,
d.\,h.\ Sie kennen nur $N$ und $e$, nicht jedoch $p$, $q$ und $d$.
Hinweis:\\
Sie können z.\,B.\ versuchen $N$ in seine Primfaktoren zu zerlegen.
Auf diese Weise können Sie zunächst $p$ und $q$ berechnen und danach $d$.
Wenn Sie die Primzahlen groß genug wählen, sollte man
unmittelbar erkennen, daß das Brechen der Verschlüsselung
\emph{wesentlich\/} länger dauert als das reguläre Ver- und
Entschlüsseln. Auf diesem Schwierigkeitsunterschied beruht
die Sicherheit der RSA-Verschlüsselung.
% \vfill
\end{itemize}
\bigskip
\strut\hfill\emph{Viel Erfolg!}
% \vspace*{4cm}
\end{multicols}
\vfill
\begingroup
\small
\setlength{\leftskip}{3cm}
Stand: 8.\ Oktober 2018
% Soweit nicht anders angegeben:\\
Copyright \copyright\ 2014, 2015, 2016, 2017, 2018\quad Peter Gerwinski\\
Lizenz: \mylicense
Sie können diese Praktikumsunterlagen einschließlich Quelltext
%% und Beispielprogramme\\
herunterladen unter:\\
\url{https://gitlab.cvh-server.de/pgerwinski/hp}
\endgroup
\end{document}
#include <stdio.h>
int main (void)
{
int a = 100;
int b = 7;
if (b != 0)
printf ("%d / %d = %d\n", a, b, a / b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 100;
int b = 0;
if (b != 0)
printf ("%d / %d = %d\n", a, b, a / b);
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 100;
int b = 0;
if (b != 0)
printf ("%d / %d = %d\n", a, b, a / b);
else
printf ("Bitte nicht durch 0 dividieren!\n");
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 100; int b = 0; if (b != 0) printf ("%d / %d = %d\n", a, b, a / b); else printf ("Bitte nicht durch 0 dividieren!\n"); return 0;
}
#include <stdio.h>
int main (void)
{
int a = 100;
int b = 0;
if (b != 0)
printf ("%d / %d = %d\n", a, b, a / b);
else
{
printf ("Bitte nicht durch 0 dividieren!\n");
printf ("Das tut man nicht.\n");
}
return 0;
}
#include <stdio.h>
int main (void)
{
int a = 100;
int b = 3;
if (b != 0)
printf ("%d / %d = %d\n", a, b, a / b);
else
printf ("Bitte nicht durch 0 dividieren!\n");
printf ("Das tut man nicht.\n");
return 0;
}
#include <stdio.h>
int main (void)
{
double a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%lf", &a);
printf ("Ihre Antwort war: %lf\n", a);
return 0;
}
#include <stdio.h>
int main (void)
{
double a;
printf ("Bitte eine Zahl eingeben: ");
scanf ("%lf", a);
printf ("Ihre Antwort war: %lf\n", a);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment