<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kryptologie Archive - Maximilian Krieg</title>
	<atom:link href="https://maximiliankrieg.de/category/studium/bachelor-of-science/4-semester-b-sc/kryptologie/feed/" rel="self" type="application/rss+xml" />
	<link>https://maximiliankrieg.de/category/studium/bachelor-of-science/4-semester-b-sc/kryptologie/</link>
	<description>Wissen, Technik &#38; Erfahrungen</description>
	<lastBuildDate>Sat, 06 Jun 2026 08:50:08 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://maximiliankrieg.de/wp-content/uploads/2026/05/cropped-20260524_logo_2_512-2-32x32.png</url>
	<title>Kryptologie Archive - Maximilian Krieg</title>
	<link>https://maximiliankrieg.de/category/studium/bachelor-of-science/4-semester-b-sc/kryptologie/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Kryptologie (Praktikum 6)</title>
		<link>https://maximiliankrieg.de/2013/06/kryptologie-praktikum-6/</link>
					<comments>https://maximiliankrieg.de/2013/06/kryptologie-praktikum-6/#respond</comments>
		
		<dc:creator><![CDATA[Maximilian]]></dc:creator>
		<pubDate>Wed, 26 Jun 2013 18:31:00 +0000</pubDate>
				<category><![CDATA[Kryptologie]]></category>
		<guid isPermaLink="false">https://maximiliankrieg.de/?p=2760</guid>

					<description><![CDATA[<p>Skript-Anfang Übungsblatt 4 &#8211; Seite 1 Skript-Ende Übungsblatt 4 &#8211; Seite 1 Aufgabe 1 Schutzziel Umsetzung Vertraulichkeit VerschlüsselungPersönliche ÜbergabeVertrauenswüdige Kuriere Integrität Message-Authentication-Codes (MAC-Verfahren)Elektronische Signaturen. Authentizität&#8230;</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-praktikum-6/">Kryptologie (Praktikum 6)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Skript-Anfang</th><td>Übungsblatt 4 &#8211; Seite 1</td></tr><tr><th>Skript-Ende</th><td>Übungsblatt 4 &#8211; Seite 1</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Aufgabe 1</h3>



<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Schutzziel</th><th>Umsetzung</th></tr><tr><td>Vertraulichkeit</td><td>VerschlüsselungPersönliche ÜbergabeVertrauenswüdige Kuriere</td></tr><tr><td>Integrität</td><td>Message-Authentication-Codes (MAC-Verfahren)Elektronische Signaturen.</td></tr><tr><td>Authentizität</td><td>MAC-Verfahren mit SignaturHändische UnterschriftInstanzauthentifizerungPerson mittels AusweisBiometrische Merkmale (Fingerabdruck)Challenge Response VerfahrenPhysikalische Sicherheitsmerkmale (Geldschein)</td></tr><tr><td>Nichtabstreitbarkeit</td><td>Elektronische SignaturHändische UnterschriftNotarielle Beglaubigung</td></tr><tr><td>Verfügbarkeit</td><td>Redundanz kritischer SystemkomponentenFehlertolerantes und robustes Verhalten des GesamtsystemsSchutz vor unberechtigter und unfachkundigem Zugriff</td></tr><tr><td>Anoynmität</td><td>Personenbezogene Daten werden so verändert, dass diese nicht oder nur mit unverhältnismäßigem Aufwand einer Person zugeordnet werden können</td></tr><tr><td>Pseudonymität</td><td>Personenbezogene Daten werden so verändert, dass diese nur unter Kenntnis der Zuordnungsvorschrift einer Person zugeordnet werden können.</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Aufgabe 2.1</h3>



<h4 class="wp-block-heading">Regeln</h4>



<ul class="wp-block-list">
<li>p und q dürfen nicht aufeinander folgen</li>



<li>e muss teilerfremd zu φ(n) sein</li>
</ul>



<h4 class="wp-block-heading">Schlüssel erzeugen</h4>



<ul class="wp-block-list">
<li>Lege fest p = 11</li>



<li>Lege fest q = 17</li>



<li>Berechne n = p * q → n = 11 * 17 = 187</li>



<li>Berechne φ(n) = |ℤ<sub>n</sub><sup>*</sup>| = (p-1)(q-1) → φ(187) = (11-1)(17-1) = 10*16 = 160</li>



<li>Lege fest e = 23</li>



<li>e*d = 1 mod 160</li>



<li>Berechne d = 7 (Solange n erhöhen bis <em>(1+160*n) / 23</em> eine ganze Zahl liefert)</li>
</ul>



<h4 class="wp-block-heading">Verschlüsselung</h4>



<ul class="wp-block-list">
<li>Lege fest m = 3</li>



<li>Berechne C = m<sup>e</sup> mod n → C = 3<sup>23</sup> mod 187 = 94.143.178.827 = 181 mod 187</li>
</ul>



<h4 class="wp-block-heading">Entschlüsselung</h4>



<ul class="wp-block-list">
<li>Gesucht m = C<sup>d</sup> = 181<sup>7</sup> mod 187</li>



<li>7 = 1*2<sup>2</sup> + 1*2<sup>1</sup> + 1*2<sup>0</sup> = ((2 + 1) * 2) + 1</li>



<li>181<sup>7</sup> = ((181)<sup>2</sup> * 181)<sup>2</sup> * 181</li>



<li>181 * 181 = 121 mod 187</li>



<li>121 * 181 = 141 mod 187</li>



<li>141 * 141 = 41 mod 187</li>



<li>41 * 181 = 3 mod 187 = m</li>
</ul>



<figure class="wp-block-image size-full"><a href="http://www.inf.fh-flensburg.de/lang/krypto/protokolle/rsa.htm"><img fetchpriority="high" decoding="async" width="782" height="796" src="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130626.png" alt="" class="wp-image-2761" srcset="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130626.png 782w, https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130626-295x300.png 295w, https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130626-768x782.png 768w" sizes="(max-width: 782px) 100vw, 782px" /></a></figure>



<h3 class="wp-block-heading">Aufgabe 2.2</h3>



<ul class="wp-block-list">
<li>Lege fest e = 3</li>



<li>Lege fest p = 5</li>



<li>Lege fest q = 11</li>



<li>Berechne n = p*q = 55</li>



<li>Lege fest m = 4</li>



<li>c<sub>1</sub> = m<sup>3</sup> mod n = 64<sup>3</sup> mod 55</li>



<li>c<sub>2</sub> = (m+1)<sup>3</sup> mod n = 4<sup>3</sup> mod 55 = 125 mod 55</li>



<li>m = (c<sub>2</sub> + 2*c<sub>1</sub> &#8211; 1) / (c<sub>2</sub> &#8211; c<sub>1</sub> + 2)</li>



<li>m = (125 + 128 &#8211; 1) / (125 &#8211; 64 + 2) = 252 / 63 = 4</li>
</ul>



<h3 class="wp-block-heading">Aufgabe 3</h3>



<h4 class="wp-block-heading">Symmetrisch</h4>



<ul class="wp-block-list">
<li>Im Hintergrund läuft PKI</li>
</ul>



<p class="wp-block-paragraph">Nutzer A:</p>



<ol class="wp-block-list">
<li>Wähle x</li>



<li>Berechne g<sup>x</sup></li>



<li>Sig(g<sup>*</sup>, sk<sub>A</sub>) = S<sub>A</sub></li>



<li>Senden → S<sub>A</sub>, g<sup>x</sup></li>



<li>Prüfe S<sub>B</sub></li>



<li>(g<sup>y</sup>)<sup>x</sup></li>
</ol>



<p class="wp-block-paragraph">Nutzer B:</p>



<ol class="wp-block-list">
<li>Wähle y</li>



<li>Berechne g<sup>y</sup></li>



<li>Sig(g<sup>y</sup>, sk<sub>B</sub>) = S<sub>B</sub></li>



<li>Senden → S<sub>B</sub>, g<sup>y</sup></li>



<li>Prüfe S<sub>A</sub></li>



<li>(g<sup>x</sup>)<sup>y</sup></li>
</ol>



<h4 class="wp-block-heading">Asymmetrisch</h4>



<ul class="wp-block-list">
<li>Diffie Hellman mit mindestens 2048 Bit</li>



<li>→ Vergleiche Abbildung 7.2</li>
</ul>



<h3 class="wp-block-heading">Aufgabe 4</h3>



<p class="wp-block-paragraph">Beispiel: Nils ruft beim Support an, weil er ein Problem mit seinem PC hat. Der Angriff erfolgt über die&nbsp;<strong>Replay-Attacke</strong>.</p>



<h4 class="wp-block-heading">Ablauf</h4>



<ol class="wp-block-list">
<li>Techniker sagt Nils er soll authentifizieren</li>



<li>Nils bekommt die Zufallszahl (Challenge)</li>



<li>Nils berechnet den Hashcode mit dem geheimen Schlüssel vom Techniker</li>



<li>Nils schickt den Hashcode zurück</li>



<li>Techniker prüft, ob der übermittelte Hashcode mit dem selbst berechneten übereinstimmt</li>



<li>Max hört zu und merkt sich den Hashcode</li>



<li>Max ruft beim Techniker an, lässt sich die Zufallszahl senden und schickt den von Nils bekannten Hashcode zurück</li>



<li>Max ist nun als Nils authentifiziert</li>
</ol>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-praktikum-6/">Kryptologie (Praktikum 6)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://maximiliankrieg.de/2013/06/kryptologie-praktikum-6/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kryptologie (Vorlesung 12)</title>
		<link>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-12/</link>
					<comments>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-12/#respond</comments>
		
		<dc:creator><![CDATA[Maximilian]]></dc:creator>
		<pubDate>Tue, 25 Jun 2013 18:22:00 +0000</pubDate>
				<category><![CDATA[Kryptologie]]></category>
		<guid isPermaLink="false">https://maximiliankrieg.de/?p=2742</guid>

					<description><![CDATA[<p>Skript-Anfang Skript &#8211; Seite 49 Skript-Ende Skript &#8211; Seite 55 Erinnerung Daten authentizitieren (z.B. Signatur) Instanzauthentisierung (über Challenge Response) Ziele Schlüsselnutzung Erste Lösung Besser &#8211;&#8230;</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-12/">Kryptologie (Vorlesung 12)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Skript-Anfang</th><td>Skript &#8211; Seite 49</td></tr><tr><th>Skript-Ende</th><td>Skript &#8211; Seite 55</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Erinnerung</h3>



<ul class="wp-block-list">
<li>Asymmetrisches Verfahren Öffentlichen Schlüssel / Public Key / PK → Verschlüsseln</li>



<li>Geheimer Schlüssel / Secret Key / SK → Entschlüsseln</li>
</ul>



<h4 class="wp-block-heading">Daten authentizitieren (z.B. Signatur)</h4>



<ul class="wp-block-list">
<li>SK → Daten signieren</li>



<li>PK → Signatur verifizieren</li>
</ul>



<h4 class="wp-block-heading">Instanzauthentisierung (über Challenge Response)</h4>



<ul class="wp-block-list">
<li>SK → Zufall (Challenge) signieren</li>



<li>PK → Signatur verifizieren</li>
</ul>



<h4 class="wp-block-heading">Ziele</h4>



<ul class="wp-block-list">
<li>Zuordnung des Schlüssels zum Schlüsselinhaber</li>



<li>Für wen verschlüssle ich eigentlich?</li>



<li>Wer hat Daten signiert?</li>



<li>Wer authentisiert sich da gerade?</li>
</ul>



<h4 class="wp-block-heading">Schlüsselnutzung</h4>



<ul class="wp-block-list">
<li>Für alle Verfahren verschiedene Schlüssel</li>



<li>Wir haben Angriffe gesehen (Sende Dokument → Bekomme es signiert zurück → Fatal!)</li>



<li>Etablieren einer gemeinsamen Sicherheitsinfrastruktur</li>



<li>Wie sicher sind Schlüssel gelagert?</li>



<li>Wie stark ist die Bindung zwischen Schlüssel und Schlüsselinhaber?</li>



<li>Wie sieht ein Registrierungsprozess aus?</li>
</ul>



<h3 class="wp-block-heading">Erste Lösung</h3>



<ul class="wp-block-list">
<li>2 Personen → 1 Austausch</li>



<li>3 Personen → 3 Austausch</li>



<li>4 Personen → 6 Austausch</li>



<li>n Personen → n(n-1)/2 Austausch</li>



<li>Kommt eine neue Personen hinzu, muss diese mit allen anderen Personen den Schlüssel austauschen</li>
</ul>



<h3 class="wp-block-heading">Besser &#8211; Public Key Infrastrukturen</h3>



<ul class="wp-block-list">
<li>Die öffentlichen Schlüssel aller Kommunikationspartner werden von einer zentralen vertrauenswürdigen Instanz verwaltet</li>



<li>Jeder Nutzer erhält ein Zertifikat für seinen öffentlichen Schlüssel</li>



<li>Zertifikat wird ausgestellt von der Certification Authority (CA)</li>
</ul>



<figure data-wp-context="{&quot;imageId&quot;:&quot;6a241258a944b&quot;}" data-wp-interactive="core/image" data-wp-key="6a241258a944b" class="wp-block-image size-full wp-lightbox-container"><img decoding="async" width="205" height="90" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130625_1.png" alt="" class="wp-image-2744"/><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.thisImage.buttonRight"
			data-wp-style--top="state.thisImage.buttonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h4 class="wp-block-heading">Aufbau eines Zertifikats</h4>



<figure data-wp-context="{&quot;imageId&quot;:&quot;6a241258a97ba&quot;}" data-wp-interactive="core/image" data-wp-key="6a241258a97ba" class="wp-block-image size-full wp-lightbox-container"><img decoding="async" width="324" height="193" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130625_2-1.png" alt="" class="wp-image-2745" srcset="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130625_2-1.png 324w, https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130625_2-1-300x179.png 300w" sizes="(max-width: 324px) 100vw, 324px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.thisImage.buttonRight"
			data-wp-style--top="state.thisImage.buttonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h4 class="wp-block-heading">Beispiel 10.1</h4>



<ol class="wp-block-list">
<li>Nutzer 1 signiert Dokument m mittels sk<sub>1</sub> → Signatur s = sig(m, sk<sub>1</sub>)</li>



<li>Nutzer 1 sendet m, s und C<sub>1</sub> an N2</li>



<li>Nutzer 2 verifiziert C<sub>1</sub> mittels pk<sub>CA</sub></li>



<li>Nutzer 2 prüft Angaben zur Person, Schlüsselnutzung und Gültigkeit</li>



<li>Nutzer 2 nutzt pk<sub>1</sub> (enthalten in C<sub>1</sub>), um s zu prüfen</li>
</ol>



<h4 class="wp-block-heading">Registration Authority (RA)</h4>



<ul class="wp-block-list">
<li>Prüft Zertifizierungsanträge</li>



<li>Legt Inhalte der Zertifikate fest</li>



<li>Leitet Anträge an die CA weiter</li>



<li>CA stellt die Zertifikate aus</li>
</ul>



<h4 class="wp-block-heading">Mehrstufige CA</h4>



<figure data-wp-context="{&quot;imageId&quot;:&quot;6a241258a9c5d&quot;}" data-wp-interactive="core/image" data-wp-key="6a241258a9c5d" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="319" height="170" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130625_3.png" alt="" class="wp-image-2746" srcset="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130625_3.png 319w, https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130625_3-300x160.png 300w" sizes="auto, (max-width: 319px) 100vw, 319px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.thisImage.buttonRight"
			data-wp-style--top="state.thisImage.buttonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h4 class="wp-block-heading">Zurückziehe von Zertifikaten</h4>



<ul class="wp-block-list">
<li>Eine Instanz (Teil CA oder ein Endnutzer) hält sich nicht an Sicherheitsvorgaben → Hierzu müssen Certification Revokation Lists (CRL) geführt werden</li>



<li>Bei Sicherheitsvorfällen (z.B. bei Schlüsselkompromittierung, Algorithmus wird unsicher )</li>



<li>Prüfung, ob Zertifikat in CRL enthalten ist</li>
</ul>



<h4 class="wp-block-heading">Certificate Policy und Certificate Practice Statement</h4>



<ul class="wp-block-list">
<li>Alle Instanzen einer PKI (z.B: Root-CA, Teil-CAs und Endnutzer) müssen ein definiertes Maß an Sicherheit einhalten</li>



<li>Root gibt dazu 2 Dokumente aus:
<ul class="wp-block-list">
<li>Certificate Policy (Öffentliches Dokument) &#8211; Welche Sicherheitsvorgaben müssen eingehalten werden</li>



<li>Certificate Practice Statement (Internes Dokument für Mitarbeiter) &#8211; Beschreibt, wie diese Sicherheitsvorgaben eingehalten werden</li>
</ul>
</li>



<li>Beispiel
<ul class="wp-block-list">
<li>Schlüssel so gesichert sein, dass sie dritten nicht zugänglich sind</li>



<li>Wir speichern Schlüssel in einem High Security Module</li>
</ul>
</li>



<li>RFC 3647 &#8211; Internet X509 Public Key Infrastructure Certificate Policy and Certification Practices Framework beschreibt Aufbau und Inhalte beider Dokumente</li>
</ul>



<h3 class="wp-block-heading">Klausur</h3>



<p class="wp-block-paragraph">Wie funktioniert die Erkennung gültiger Zertifikate und eines signierten Dokumentes von Benutzern, die zu einer anderen Teil-CA gehören?</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-12/">Kryptologie (Vorlesung 12)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-12/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kryptologie (Vorlesung 11)</title>
		<link>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-11/</link>
					<comments>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-11/#respond</comments>
		
		<dc:creator><![CDATA[Maximilian]]></dc:creator>
		<pubDate>Tue, 18 Jun 2013 18:21:00 +0000</pubDate>
				<category><![CDATA[Kryptologie]]></category>
		<guid isPermaLink="false">https://maximiliankrieg.de/?p=2740</guid>

					<description><![CDATA[<p>Skript-Anfang Skript &#8211; Seite 43 Skript-Ende Skript &#8211; Seite 45 Zufallszahlengeneratoren Zweck Wichtig Entropie Physikalische Generatoren Zufall aus physikalischen Rauschquellen Probleme Lösung Sicherheit (BSI-Empfehlung) Beispiel&#8230;</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-11/">Kryptologie (Vorlesung 11)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Skript-Anfang</th><td>Skript &#8211; Seite 43</td></tr><tr><th>Skript-Ende</th><td>Skript &#8211; Seite 45</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Zufallszahlengeneratoren</h3>



<h4 class="wp-block-heading">Zweck</h4>



<ul class="wp-block-list">
<li>Schlüsselgenerierung</li>



<li>Asymmetrischen Verschlüsselungsverfahren (<strong>Padding für RSA</strong>)</li>



<li>Zufall im Challenge-Response-Verfahren</li>
</ul>



<h4 class="wp-block-heading">Wichtig</h4>



<ul class="wp-block-list">
<li>Die Güte des Zufalls, die&nbsp;<strong>Unvorhersagbarkeit</strong>&nbsp;→ mit x<sub>1</sub>, &#8230; , x<sub>128</sub>&nbsp;∈ {0,1}</li>



<li>Sicherheitsniveau ist 2<sup>100</sup>&nbsp;Versuche = 1/2<sup>100</sup></li>
</ul>



<h3 class="wp-block-heading">Entropie</h3>



<ul class="wp-block-list">
<li>Wird in Bit gemessen</li>



<li>&#8222;<em>Entropie von n Bit</em>&#8220; bedeutet die Wahrscheinlichkeit den Zufallswert zu erraten, ist 1 / (2<sup>n</sup>)</li>



<li>Schlüssel (x<sub>1</sub>&nbsp;, &#8230; , x<sub>128</sub>) benötigt eine Entropie von 100 Bit</li>



<li>Schlüssel der Länge 128 Bit mit Entropie von 128 Bit bedeutet, dass jedes Bit im Schlüssel hat Entropie von 1 Bit
<ul class="wp-block-list">
<li>Pr(x<sub>1</sub>=0) = 1/2</li>



<li>Pr(x<sub>1</sub>=1)=1/2</li>
</ul>
</li>



<li>Wir unterscheiden hier zwischen physikalischen und deterministischen Zufallsgeneratoren</li>
</ul>



<h3 class="wp-block-heading">Physikalische Generatoren</h3>



<h4 class="wp-block-heading">Zufall aus physikalischen Rauschquellen</h4>



<ul class="wp-block-list">
<li>Impulsschwankungen elektromagnetischer Schaltungen</li>



<li>radioaktiver Zerfall</li>



<li>Atmosphärenrauschen</li>
</ul>



<h4 class="wp-block-heading">Probleme</h4>



<ul class="wp-block-list">
<li>Nicht immer verfügbar</li>



<li>Häufig langsam, die Zeit bis genug Zufall gesammelt wurde ist lang</li>



<li>Häufige&nbsp;<strong>Schiefen</strong>&nbsp;(mehr Einsen als Nullen oder umgekehrt → Keine Gleichverteilung)</li>



<li>Eine Schiefe, die Wahrscheinlichkeit aufzutreten, bedeutet, dass die Wahrscheinlichkeit größer als 1/2 ist</li>
</ul>



<h4 class="wp-block-heading">Lösung</h4>



<ul class="wp-block-list">
<li>Deterministische Nachbearbeitung</li>
</ul>



<h4 class="wp-block-heading">Sicherheit (BSI-Empfehlung)</h4>



<ol class="wp-block-list">
<li>Beschreiben der Rauschquellen durch ein stochastisches Modell</li>



<li>Der durchschnittliche Entropiezuwachs pro Zufallsbit liegt oberhalb einer gegebenen Mindestschranke</li>
</ol>



<h4 class="wp-block-heading">Beispiel</h4>



<ul class="wp-block-list">
<li>Erzeugt wird eine Zufallsfolge x<sub>1</sub>&nbsp;, &#8230; , x<sub>n</sub>&nbsp;∈ {0,1}</li>



<li>Entropiezuwachs pro Bit → Ideal = 1</li>



<li>Wahrscheinlichkeit x<sub>1</sub>&nbsp;zu erraten = 1/2</li>



<li>Wahrscheinlichkeit alles zu erraten = 1/(2<sup>n</sup>)</li>



<li><strong>Häufige Schiefen:</strong>
<ul class="wp-block-list">
<li>Pr(x<sub>1</sub>=0)=0,2</li>



<li>Pr(x<sub>1</sub>=1)=0,8</li>
</ul>
</li>



<li><strong>Entropie von x<sub>1</sub>:</strong>
<ul class="wp-block-list">
<li>Wahrscheinlichkeit x<sub>1</sub>&nbsp;zu erraten ist 0,8</li>



<li>Ausgedrückt in Entropie: 1/2<sup>x</sup>&nbsp;= 0,8</li>



<li>x = 0,322 ≈1/3</li>



<li>Um 100 Bit Entropie zu erhalten, müssen x<sub>1</sub>&nbsp;bis x<sub>300</sub>&nbsp;erzeugt werden</li>
</ul>
</li>



<li><strong>Deterministische Nachbearbeitung:</strong>
<ul class="wp-block-list">
<li>Aus&nbsp;<strong>300 Bit mit Entropie 100</strong>&nbsp;mache&nbsp;<strong>100 Bit mit Entropie 100</strong></li>
</ul>
</li>
</ul>



<h3 class="wp-block-heading">Deterministische Zufallsgeneratoren</h3>



<ul class="wp-block-list">
<li>Werden auch Pseudozufallsgeneratoren genannt</li>



<li>Berechnen aus einem Zufallswert mit fester Länge, auch&nbsp;<strong>Seed</strong>&nbsp;genannt</li>



<li>Der Seed ist eine Pseudozufällige Bitfolge praktisch beliebiger Länge</li>
</ul>



<h4 class="wp-block-heading">Hinweis</h4>



<ul class="wp-block-list">
<li>Durch einen deterministischen Zufallsgenerator bzw. Nachbearbeitung kann die Entropie, die Zufälligkeit, nicht erhöht werden</li>



<li>Je komplizierter der Generator ist, desto schwieriger ist es nachzuweisen, ob dieser wirklich funktioniert und sicher ist</li>



<li><strong>Wiederverwendbarkeit:</strong>
<ul class="wp-block-list">
<li><em>&#8222;Die Wiederverwendbarkeit des Seeds tritt ab zweitem Schritt auf.&#8220;</em></li>



<li>Für hashfunktion h : {0,1}<sup>*</sup>&nbsp;→ {0,1}<sup>200</sup>&nbsp;erzeugt dieser deterministischer Zufallsgenerator in jedem Schritt 200 Bit Zufall mit Entropie min {200, Entropie (SEED)}</li>
</ul>
</li>
</ul>



<figure data-wp-context="{&quot;imageId&quot;:&quot;6a241258ac26a&quot;}" data-wp-interactive="core/image" data-wp-key="6a241258ac26a" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="500" height="95" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://maximiliankrieg.de/wp-content/uploads/2013/06/kyl_20130618_1.png" alt="" class="wp-image-2807" srcset="https://maximiliankrieg.de/wp-content/uploads/2013/06/kyl_20130618_1.png 500w, https://maximiliankrieg.de/wp-content/uploads/2013/06/kyl_20130618_1-300x57.png 300w" sizes="auto, (max-width: 500px) 100vw, 500px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.thisImage.buttonRight"
			data-wp-style--top="state.thisImage.buttonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h4 class="wp-block-heading">Sicherheit</h4>



<ul class="wp-block-list">
<li>Entropieerhaltend</li>



<li>Aus bekannter Zufallsfolge dürfen Vorgänger und Nachfolger nicht berechnet werden</li>
</ul>



<h3 class="wp-block-heading">Seedgenerierung</h3>



<ul class="wp-block-list">
<li>Seed durch phyiskalische Zufallsgeneratoren generieren</li>



<li>Am Computer durch mehrere&nbsp;<strong>unabhängige</strong>&nbsp;Systemaufrufe zusammen setzen</li>



<li><strong>Linux /dev/random:</strong>
<ul class="wp-block-list">
<li>Liefert mindestens 100 Bit Entropie (laut BSI)</li>



<li>Systemzeit, Nutzeraktivitäten (Programm öffnen, Fenster schließen, Mausposition)</li>
</ul>
</li>



<li><strong>Windows:</strong>
<ul class="wp-block-list">
<li>Kombination verschiedener Systemaufrufe</li>



<li>Read Time Stamp Counter() = Prozessorzyklen seit Systemstart</li>



<li>Bei Taktfrequenz ≥ 1 GHz → 2<sup>30</sup>&nbsp;mögliche Werte pro Sekunde (<strong>Nicht 2<sup>30</sup>&nbsp;lang!</strong>)</li>



<li>KeQuerySystemTime() = Aktuelle Systemzeit (relativ zu 1970)</li>



<li>Auflösung beträgt 100ms → 2<sup>23</sup>&nbsp;verschiedene Werte pro Sekunde</li>
</ul>
</li>
</ul>



<h4 class="wp-block-heading">Erzeugung</h4>



<ol class="wp-block-list">
<li>Starte Rechner</li>



<li>Starte Programm
<ul class="wp-block-list">
<li>A = RTSC();</li>



<li>B = KQST();</li>
</ul>
</li>



<li>Verifizieren eines Logins
<ul class="wp-block-list">
<li>C = RTSC();</li>



<li><del>C&#8216; = KQST();&nbsp;</del>← Lässt sich aus den anderen Aufrufen berechnen und bringt nichts mehr</li>
</ul>
</li>



<li>Erzeugen des SEEDs
<ul class="wp-block-list">
<li>D = RTSC();</li>



<li>A||B||C||D = SEED</li>
</ul>
</li>



<li>Erzeugter Seed hat eine Entropie von
<ul class="wp-block-list">
<li>30+23+30+30 = 113</li>
</ul>
</li>
</ol>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-11/">Kryptologie (Vorlesung 11)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-11/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kryptologie (Praktikum 5)</title>
		<link>https://maximiliankrieg.de/2013/06/kryptologie-praktikum-5/</link>
					<comments>https://maximiliankrieg.de/2013/06/kryptologie-praktikum-5/#respond</comments>
		
		<dc:creator><![CDATA[Maximilian]]></dc:creator>
		<pubDate>Wed, 12 Jun 2013 18:31:00 +0000</pubDate>
				<category><![CDATA[Kryptologie]]></category>
		<guid isPermaLink="false">https://maximiliankrieg.de/?p=2758</guid>

					<description><![CDATA[<p>Inhalt Es gibt keine Aufgaben bis zum nächsten Praktikumstermin. Skript-Anfang Kryptouebung3 &#8211; Seite 1 Skript-Ende Kryptouebung3 &#8211; Seite 1</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-praktikum-5/">Kryptologie (Praktikum 5)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">Inhalt</h3>



<p class="wp-block-paragraph">Es gibt keine Aufgaben bis zum nächsten Praktikumstermin.</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Skript-Anfang</th><td>Kryptouebung3 &#8211; Seite 1</td></tr><tr><th>Skript-Ende</th><td>Kryptouebung3 &#8211; Seite 1</td></tr></tbody></table></figure>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-praktikum-5/">Kryptologie (Praktikum 5)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://maximiliankrieg.de/2013/06/kryptologie-praktikum-5/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kryptologie (Vorlesung 10)</title>
		<link>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-10/</link>
					<comments>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-10/#respond</comments>
		
		<dc:creator><![CDATA[Maximilian]]></dc:creator>
		<pubDate>Tue, 11 Jun 2013 18:20:00 +0000</pubDate>
				<category><![CDATA[Kryptologie]]></category>
		<guid isPermaLink="false">https://maximiliankrieg.de/?p=2737</guid>

					<description><![CDATA[<p>Skript-Anfang Skript &#8211; Seite 36 Skript-Ende Skript &#8211; Seite 37 Wiederholung Beispiele für Gruppen zum DL Eigenschaften Angriff Erfolgreicher Angriff &#8211; Man in the middle&#8230;</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-10/">Kryptologie (Vorlesung 10)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Skript-Anfang</th><td>Skript &#8211; Seite 36</td></tr><tr><th>Skript-Ende</th><td>Skript &#8211; Seite 37</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Wiederholung</h3>



<ul class="wp-block-list">
<li>Diskretes Logarithmusproblem (Siehe Mitschrift vom 04.06.2011)</li>



<li>Symmetrische Schlüssel zum Erreichen des gleichen Sicherheitsniveaus sind kürzer als asymmetrische Schlüssel</li>
</ul>



<h4 class="wp-block-heading">Beispiele für Gruppen zum DL</h4>



<ul class="wp-block-list">
<li>ℤ<sub>p</sub><sup>*</sup>&nbsp;= {1, &#8230; , p-1}</li>
</ul>



<h4 class="wp-block-heading">Eigenschaften</h4>



<ul class="wp-block-list">
<li><strong>Zyklisch:</strong>
<ul class="wp-block-list">
<li>Es gibt ein g ∈ ℤ<sub>p</sub><sup>*</sup>&nbsp;mit {1, &#8230; , p-1} = {g<sup>n</sup>, n ∈ ℕ}</li>



<li>Gruppe ℤ<sub>5</sub><sup>*</sup>&nbsp;= {1, 2, 3, 4}</li>



<li>3 ist&nbsp;<strong>ein</strong>&nbsp;Erzeuger (Das Verfahren zum Herausfinden folgt später)</li>



<li>4 ist&nbsp;<strong>kein</strong>&nbsp;Erzeuger (Nicht jede Zahl in der Gruppe ist auch ein Erzeuger für diese Gruppe)</li>



<li>Ist g ∈ ℤ<sub>p</sub>* ein Erzeuger, dann existiert für alle h ∈ ℤ<sub>p</sub><sup>*</sup>&nbsp;ein x ∈ ℕ mit g<sup>x</sup>&nbsp;= h</li>



<li>Dies bedeutet, dass log<sub>g</sub>h = x existiert</li>
</ul>
</li>



<li>Daran lassen sich dann Schlüssel ableiten, z.B. für Secure Messaging (verschlüsselte und authentisierte Kommunikation)
<ul class="wp-block-list">
<li>K<sub>E</sub>&nbsp;= Hashwert H (g<sup>xy</sup>&nbsp;|| 0x00) Verschlüsselungsschlüssel</li>



<li>K<sub>E</sub>&nbsp;= Hashwert H (g<sup>xy</sup>&nbsp;|| 0x01) Schlüssel für Authentisierung</li>
</ul>
</li>
</ul>



<h4 class="wp-block-heading">Angriff</h4>



<ul class="wp-block-list">
<li>Angreifer kennt g, g<sup>x</sup>, g<sup>y</sup></li>



<li>Ziel ist es das gemeinsame Geheimnis g<sup>xy</sup>&nbsp;heraus zu finden</li>



<li><strong>Derzeitig einzige Möglichkeit:</strong>
<ul class="wp-block-list">
<li>Bestimme x oder y, d.h. berechne log<sub>g</sub>(g<sup>x</sup>) = y oder log<sub>g</sub>(g<sup>y</sup>) = x</li>
</ul>
</li>



<li>Erster Ansatz über Probepotenzieren (Brute Force):
<ol class="wp-block-list">
<li>Wähle x&#8216;, berechne g<sup>x&#8216;&nbsp;</sup>und vergleiche mit g<sup>x&#8216;</sup>&nbsp;= gx</li>



<li>Für p &gt; 2<sup>100&nbsp;</sup>ist |ℤ<sub>p</sub>*| &gt; 2<sup>100</sup></li>



<li>D.h. Wahrscheinlichkeit für Gleichheit kleiner als 2<sup>-100</sup>&nbsp;bzw. 1/2<sup>100</sup></li>



<li>Man braucht also ca. 2<sup>100&nbsp;</sup>Versuche x zu finden (<strong>Sicherheitsniveau ist 100 Bit</strong>)</li>



<li>Schnellster Algorithmus für das DLP (Diskretes Logarithmusproblem) O(e<sup>sqrt(log<sub>10</sub>(p) * log<sub>10</sub>(log<sub>10</sub>p))</sup>)</li>



<li>p ≈ 2<sup>4000</sup>&nbsp;gilt log<sub>10</sub>(2<sup>4000</sup>) ≈ 1200</li>



<li>log<sub>10</sub>(log<sub>10</sub>&nbsp;(2<sup>4000</sup>) ≈ 3</li>



<li>sqrt(1200*3) = e<sup>60</sup>&nbsp;= 2<sup>90</sup></li>
</ol>
</li>
</ul>



<h4 class="wp-block-heading">Erfolgreicher Angriff &#8211; Man in the middle</h4>



<figure data-wp-context="{&quot;imageId&quot;:&quot;6a241258ae95b&quot;}" data-wp-interactive="core/image" data-wp-key="6a241258ae95b" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="381" height="299" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://maximiliankrieg.de/wp-content/uploads/2013/06/kyl_20130611_1.png" alt="" class="wp-image-2805" srcset="https://maximiliankrieg.de/wp-content/uploads/2013/06/kyl_20130611_1.png 381w, https://maximiliankrieg.de/wp-content/uploads/2013/06/kyl_20130611_1-300x235.png 300w" sizes="auto, (max-width: 381px) 100vw, 381px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.thisImage.buttonRight"
			data-wp-style--top="state.thisImage.buttonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<ul class="wp-block-list">
<li><strong>Also:&nbsp;</strong>Das Verfahren muss mit Instanzauthentisierung einher gehen, um g<sup>x</sup>&nbsp;/ g<sup>y</sup>&nbsp;den Kommunikationspartner zuordnen zu können</li>
</ul>



<h3 class="wp-block-heading">Secret Sharing</h3>



<ul class="wp-block-list">
<li><strong>Ziel:</strong>&nbsp;Durchsetzung eines Mehr-Augen-Prinzips</li>



<li>Aufteilen eines Geheimnisses K (z.B. kryptographischer Schlüssel) in n Teilgeheimnisse so, dass</li>



<li>t ≤ n Teilgeheimnisse notwendig sind um K zu erhalten</li>



<li>t-1 Teile aber keinerlei Informationen über K liefern</li>
</ul>



<h3 class="wp-block-heading"><strong>(t, n) &#8211; Schwellwert &#8211; Schema</strong></h3>



<ul class="wp-block-list">
<li>(4,10) = Ich brauche 4 von 10 Teilen</li>
</ul>



<h4 class="wp-block-heading">Einfaches und unsicheres Verfahren:</h4>



<ul class="wp-block-list">
<li>128 bit Schlüssel in z.B. 4 Teile aufteilen</li>



<li>K = {K<sub>1</sub>, &#8230; , K<sub>22</sub>&nbsp;, &#8230; , K<sub>128</sub>}</li>



<li>K<sub>1</sub>&nbsp;bis K<sub>2</sub>2 = Teilschlüssel 1, usw.</li>



<li>Mit 3 Teilen des Schlüssels ließen sich z.B. schon 96 Bit wieder herstellen, d.h. es werden Informationen über K geliefert</li>
</ul>



<h4 class="wp-block-heading">Einfaches und sicheres Verfahren</h4>



<ol class="wp-block-list">
<li>Wähle zufällig n-1 Werte TK<sub>1</sub>, &#8230; , TK<sub>n-1</sub>&nbsp;= {0,1}<sup>128</sup></li>



<li>Setze T,K<sub>n</sub>&nbsp;= TK<sub>1</sub>&nbsp;⊕ &#8230; ⊕ TK<sub>n-1</sub>&nbsp;⊕ K</li>



<li>Dann gilt TK<sub>1</sub>&nbsp;⊕ &#8230; ⊕ TK<sub>n</sub>&nbsp;= K</li>



<li>Kennt man weniger als n Teilgeheimnisse erhält man keine Informationen über den Schlüssel K</li>



<li>Vergleichbar zum&nbsp;<strong>One-time-pad</strong></li>
</ol>



<h4 class="wp-block-heading">Shamirs Secret Sharing (R<ins><strong>S</strong></ins>A) &#8211; (t,n)</h4>



<ul class="wp-block-list">
<li><strong>Idee:</strong>&nbsp;Verstecke K in einem Polyom</li>



<li>Betrachte k ∈ {0,1}<sup>128</sup>&nbsp;als natürliche Zahl \( k = \sum_{i=1}^{128} * K_i * 2^{i-1}\)</li>



<li>Wähle k-1 zufällig Werte a<sub>1</sub>, &#8230; , a<sub>t-1</sub></li>



<li>Betrachte f(x) = K + a<sub>1</sub>&nbsp;x<sup>1</sup>&nbsp;+ a<sub>2</sub>x<sup>2</sup>&nbsp;+ &#8230; + a<sub>t-1</sub>&nbsp;x<sup>t-1</sup></li>



<li>Dann gilt f(0) = K</li>



<li><strong>Erzeugen der Geheimnisse:</strong>
<ul class="wp-block-list">
<li>Pers 1 → (1,f(1))</li>



<li>Pers 2 → (2,f(2))</li>



<li>&#8230;</li>



<li>Pers n → (n,f(n))</li>
</ul>
</li>



<li>Lösche a<sub>1</sub>&nbsp;bis a<sub>t-1</sub></li>



<li><strong>Rekonstruktion des Polynoms:</strong><ul><li>Fundamentalsatz der Algebra: Polynom (t-1) Grades wird durch t Punkte (x<sub>i</sub>, f(x<sub>i</sub>)) ist eindeutig festgelegt</li><li>Es werden also t der n zuvor berechneten Werte benötigt</li><li>\( f(x) = \sum_{i=1}^{t}f(x_i) * \prod_{j=1 \wedge y\neq i }^{t}\frac{x-x_j}{x_i-x_j} \) (Lagrange-Formel)</li></ul>Sicherheit
<ul class="wp-block-list">
<li>t-1 (und weniger) Teile liefern keinerlei Informationen über k</li>



<li>Angreifer kennt t-1 Werte (1,f(1)) , &#8230; , (t-1, f(t-1))</li>



<li>\( K=f(0)=\sum_{i=1}^{t}f(i)*\prod_{j=1 \wedge j\neq i}^{t}\frac{0-j}{i-j} \)</li>



<li>\( K=f(0)=\sum_{i=1}^{t-1}f(i)*\prod_{j=1 \wedge j\neq i}^{t-1}\frac{0-j}{i-j} + f(t)*\prod_{j=1 \wedge j\neq i}^{t}\frac{0-j}{t-j} \)</li>



<li>Nur f(t) ist nicht bekannt</li>



<li>f(t) kann alle möglichen Werte annehmen, damit auch f(0) = K</li>



<li>D.h. Angreifer hat keinerlei Informationen über K</li>
</ul>
</li>
</ul>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-10/">Kryptologie (Vorlesung 10)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-10/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kryptologie (Vorlesung 9)</title>
		<link>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-9/</link>
					<comments>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-9/#respond</comments>
		
		<dc:creator><![CDATA[Maximilian]]></dc:creator>
		<pubDate>Tue, 04 Jun 2013 18:19:00 +0000</pubDate>
				<category><![CDATA[Kryptologie]]></category>
		<guid isPermaLink="false">https://maximiliankrieg.de/?p=2734</guid>

					<description><![CDATA[<p>Skript-Anfang Skript &#8211; Seite 36 Skript-Ende Skript &#8211; Seite 37 Instanzauthentisierung Challenge Response Verfahren Grundlage (kryptographische Primitive) &#8211; Verfahren zur Datenauthentisierung Nutzung von symmetrischen Verfahren&#8230;</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-9/">Kryptologie (Vorlesung 9)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Skript-Anfang</th><td>Skript &#8211; Seite 36</td></tr><tr><th>Skript-Ende</th><td>Skript &#8211; Seite 37</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Instanzauthentisierung</h3>



<ul class="wp-block-list">
<li><em>&#8222;Ist mein Gegenüber derjenige, der er vorgibt zu sein&#8220;</em> → Schutzziel Authentizität (Siehe <strong>Definition 1.3</strong>)</li>



<li>Beweisender (derjenige, der sich authentisieren will) weist dem Prüfer den Besitz eines Geheimnisses nach</li>



<li><strong>Typisches Beispiel: </strong>Benutzername und Kennwert</li>
</ul>



<h3 class="wp-block-heading">Challenge Response Verfahren</h3>



<ul class="wp-block-list">
<li>Siehe <strong>Abbildung 6.1</strong></li>



<li>Kommt z.B. bei SSL und HTTPS zum Einsatz</li>
</ul>



<figure data-wp-context="{&quot;imageId&quot;:&quot;6a241258b069d&quot;}" data-wp-interactive="core/image" data-wp-key="6a241258b069d" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="711" height="271" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130406.png" alt="" class="wp-image-2735" srcset="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130406.png 711w, https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130406-300x114.png 300w" sizes="auto, (max-width: 711px) 100vw, 711px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.thisImage.buttonRight"
			data-wp-style--top="state.thisImage.buttonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h3 class="wp-block-heading">Grundlage (kryptographische Primitive) &#8211; Verfahren zur Datenauthentisierung</h3>



<h4 class="wp-block-heading">Nutzung von symmetrischen Verfahren (MAC)</h4>



<ul class="wp-block-list">
<li>Zu P und B muss vorab ein symmetrischer Schlüssel ausgetauscht werden</li>



<li>B weist im Rahmen des Protokolls nach, dass er den Schlüssel kennt ohne diesen zu übermitteln</li>
</ul>



<h4 class="wp-block-heading">Nutzung von asymmetrischen Verfahren (Signatur)</h4>



<ol class="wp-block-list">
<li>B nutzt zur Berechnung der Prüfsumme seinen geheimen Schlüssel</li>



<li>P prüft mittels zugehörigem öffentlichen Schlüssel</li>



<li>P muss den öffentlichen Schlüssel dem B zuordnen können (benötigt <strong>Public-Key-Infrastruktur</strong>)</li>
</ol>



<h4 class="wp-block-heading">Wichtig</h4>



<ul class="wp-block-list">
<li>Schlüssel für Datenauthentisierung und Instanzauthentisierung müssen verschieden sein</li>
</ul>



<h4 class="wp-block-heading">Angriff</h4>



<ul class="wp-block-list">
<li>Angreifer erzeugt eine Nachricht m und bildet M(m) = r</li>



<li>Angreifer fordert B zur Authentisierung auf und sendet r</li>



<li>B berechnet die Prüfsumme c</li>



<li>B sieht nicht, ob r Zufall oder Hashwort einer Nachricht ist</li>



<li>Beim Angreifer liegt eine von B korrekt signierte Nachricht vor</li>
</ul>



<h3 class="wp-block-heading">Schlüsseleingangsverfahren</h3>



<ul class="wp-block-list">
<li>Ziel ist es den Austausch bzw. die Einigung von Schlüsseln über unsichere Kanäle sicher zu gestalten</li>



<li><strong>Beispiel</strong>:
<ol class="wp-block-list">
<li>A möchte B ein Geheimnis schicken</li>



<li>Fährmann F ist aber nicht vertrauenswürdig</li>



<li>A sichert Kiste mit Schloss 1</li>



<li>F übergibt Kiste an B</li>



<li>B sichert mit Schloss 2</li>



<li>F übergibt Kiste an A</li>



<li>A öffnet Schloss 1</li>



<li>F übergibt B die Kiste</li>



<li>B kann die Kiste öffnen</li>
</ol>
</li>



<li>Das Verfahren ist jedoch nicht sicher, da A nicht weiß (sobald er F aus den Augen verliert) ob F nicht das Schloss 2 anbringt und sich als B ausgibt → Man in the Middle</li>



<li>Über <strong>authentische Schlösser</strong> ist gewährleistet, dass Schloss 2 zu B gehört</li>
</ul>



<h4 class="wp-block-heading">Mögliche Verfahren</h4>



<ul class="wp-block-list">
<li>Einsatz von symmetrischen und asymmetrischen Verschlüsselungsverfahren</li>



<li>Regelmäßiger Austausch kryptographischer Schlüssel, um Folgen von Schlüsselkompromittierungen gering zu halten</li>



<li><strong>Neue Idee:</strong>
<ul class="wp-block-list">
<li>Diffie-Hellmann-Schlüsseleingangsverfahren (Diffie-Hellmann, Meckle)</li>



<li>Das Verfahren beruht auf der vermuteten Schwierigkeit des Diskreten Logarithmusproblems in bestimmten Gruppen.</li>
</ul>
</li>
</ul>



<h4 class="wp-block-heading">Diskretes Logarithmusproblem</h4>



<ul class="wp-block-list">
<li><strong>Eingabe:</strong> Zwei Zahlen g, h ∈ G</li>



<li><strong>Ausgabe:</strong> log<sub>a</sub>h, d.h. x ∈ ℕ mit g<sup>x</sup> = h</li>



<li>Eine Gruppe G heißt kryptographisch stark, wenn das DL-Problem in G praktisch nicht lösbar ist (Sicherheitsniveau 100 bit)</li>



<li>Für solche Gruppen ℤ<sub>p</sub><sup>*</sup> = {1 , &#8230; , p-1}, p sehr große Primzahl (a * b = a * b mod p)</li>



<li><strong>Eigenschaften:</strong>
<ul class="wp-block-list">
<li>Diese Gruppen sind zyklisch, d.h. es gibt g ∈ ℤ<sub>p</sub><sup>*</sup> mit {g<sup>n</sup>, n ∈ ℕ} = {1, 2, &#8230; , p-1}</li>



<li>g ist dann Erzeuger der Gruppe insbesondere ℤ<sub>p</sub><sup>*</sup> = {g<sup>n</sup>, ≤ n ≤ p-1}</li>
</ul>
</li>



<li><strong>Beispiele:</strong>
<ul class="wp-block-list">
<li>ℤ<sub>5</sub><sup>*</sup> = {1, 2, 3, 4}</li>



<li>3<sup>1</sup> = <strong>3</strong> mod 5</li>



<li>3<sup>2</sup> = 9 = <strong>4</strong> mod 5</li>



<li>3<sup>3</sup> = 27 = <strong>2</strong> mod 5</li>



<li>3<sup>4</sup> = 81 = <strong>1</strong> mod 5</li>



<li>2 und 3 sind Erzeuger</li>



<li>1 und 4 sind keine Erzeuger (können alle Zahlen erzeugen)</li>
</ul>
</li>
</ul>



<h4 class="wp-block-heading">Angriff</h4>



<ol class="wp-block-list">
<li>Öffentlich bekannt g<sup>x</sup>, g<sup>y</sup>, g</li>



<li>Angreifer berechnet log<sub>g</sub>(g<sup>x</sup>) = x</li>



<li>Angreifer berechnet (g<sup>y</sup>)<sup>x</sup> = g<sup>xy</sup></li>
</ol>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-9/">Kryptologie (Vorlesung 9)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://maximiliankrieg.de/2013/06/kryptologie-vorlesung-9/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kryptologie (Klausurvorbereitung)</title>
		<link>https://maximiliankrieg.de/2013/06/kryptologie-klausurvorbereitung/</link>
					<comments>https://maximiliankrieg.de/2013/06/kryptologie-klausurvorbereitung/#respond</comments>
		
		<dc:creator><![CDATA[Maximilian]]></dc:creator>
		<pubDate>Sun, 02 Jun 2013 18:24:00 +0000</pubDate>
				<category><![CDATA[Kryptologie]]></category>
		<guid isPermaLink="false">https://maximiliankrieg.de/?p=2748</guid>

					<description><![CDATA[<p>Im Rahmen der Klausurvorbereitung wurden alle Kernthemen des Skriptes erneut besprochen. Alle Themenbereiche sind Bestandteil der Klausur. Skript-Anfang Skript &#8211; Seite 1 Skript-Ende Skript &#8211;&#8230;</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-klausurvorbereitung/">Kryptologie (Klausurvorbereitung)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Im Rahmen der Klausurvorbereitung wurden alle Kernthemen des Skriptes erneut besprochen. Alle Themenbereiche sind Bestandteil der Klausur.</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Skript-Anfang</th><td>Skript &#8211; Seite 1</td></tr><tr><th>Skript-Ende</th><td>Skript &#8211; Seite 66</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Schwerpunkte der Klausur</h3>



<ol class="wp-block-list">
<li>Symmetrische und Asymmetrische Verschlüsselung</li>



<li>Funktionsweise von Blockchiffren und RSA</li>



<li>Schlüsseleinigungsverfahren</li>



<li>Angriffsmöglichkeiten wie &#8222;Man in the Middle&#8220;</li>



<li>Public Key Infrastruktur</li>
</ol>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/06/kryptologie-klausurvorbereitung/">Kryptologie (Klausurvorbereitung)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://maximiliankrieg.de/2013/06/kryptologie-klausurvorbereitung/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kryptologie (Praktikum 4)</title>
		<link>https://maximiliankrieg.de/2013/05/kryptologie-praktikum-4/</link>
					<comments>https://maximiliankrieg.de/2013/05/kryptologie-praktikum-4/#respond</comments>
		
		<dc:creator><![CDATA[Maximilian]]></dc:creator>
		<pubDate>Wed, 29 May 2013 18:30:00 +0000</pubDate>
				<category><![CDATA[Kryptologie]]></category>
		<guid isPermaLink="false">https://maximiliankrieg.de/?p=2756</guid>

					<description><![CDATA[<p>Skript-Anfang Kryptouebung3 &#8211; Seite 1 Skript-Ende Kryptouebung3 &#8211; Seite 1 main.cpp myAES.h myAES.cpp myCBC.h myCBC.cpp myECB.h myECB.cpp myGUI.h myGUI.cpp support.h</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/05/kryptologie-praktikum-4/">Kryptologie (Praktikum 4)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Skript-Anfang</th><td>Kryptouebung3 &#8211; Seite 1</td></tr><tr><th>Skript-Ende</th><td>Kryptouebung3 &#8211; Seite 1</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">main.cpp</h3>



<pre class="wp-block-code"><code>
#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include "myGUI.h"


// Using-Deklarationen
using namespace std;

int main(int argc, char** argv) {
    //Start GUI
    myGUI gui;
}// main
</code></pre>



<h3 class="wp-block-heading">myAES.h</h3>



<pre class="wp-block-code"><code>
#ifndef MYAES_H
#define	MYAES_H

#include &lt;iostream&gt;

using namespace std;
// Typedefs
typedef unsigned char uchar;

class myAES {
public:
    // Konstruktoren/Destruktoren
    myAES();
    virtual ~myAES();

    // Manuelle Eingabe
    void enterKlartext();
    void enterSchluessel();

    // Set/Get-Methoden
    void setKlartext(uchar&#91;16]);
    void setSchluessel(uchar&#91;16]);
    void setCiphertext(uchar&#91;16]);
    uchar* getKlartext();
    uchar* getSchluessel();
    uchar* getCiphertext();

    // Crypt
    void crypt(bool);
    void mixcolumns();
    void shiftrows();
    void schluesselexpansion(uchar&#91;]&#91;44], int, int, int);
    void rotword(uchar&#91;], int);
    uchar mix(uchar, unsigned int);
    void subbytes(uchar &#91;], uchar &#91;], int);
    
    // Decrypt
    void decrypt(bool);
    uchar gmul(uchar, uchar);
    void invert_mixcolumns();
    void invert_shiftrows();    
    
private:
    uchar klartext&#91;16];
    uchar schluessel&#91;16];
    uchar ciphertext&#91;16];
};



#endif	/* MYAES_H */
</code></pre>



<h3 class="wp-block-heading">myAES.cpp</h3>



<pre class="wp-block-code"><code>
#include "myAES.h"

using namespace std;

//&lt;editor-fold defaultstate="collapsed" desc="Boxen"&gt;

unsigned char Sbox&#91;256] = {//  s-box
    0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
    0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
    0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
    0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
    0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
    0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
    0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
    0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
    0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
    0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
    0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
    0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
    0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
    0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
    0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
    0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
};

unsigned char sbox_inverse&#91;256] = {
    0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
    0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
    0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
    0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
    0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
    0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
    0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
    0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
    0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
    0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
    0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
    0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
    0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
    0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
    0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
    0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
};

unsigned char Rcon&#91;256] = {
    0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a,
    0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39,
    0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
    0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8,
    0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef,
    0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
    0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b,
    0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3,
    0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
    0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
    0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35,
    0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
    0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04,
    0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63,
    0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
    0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d
};
//&lt;/editor-fold&gt;

//&lt;editor-fold defaultstate="collapsed" desc="AES-Methoden"&gt;

void myAES::subbytes(uchar sbox&#91;], uchar tmp&#91;], int arrSize) {
    for (int i = 0; i &lt; arrSize; i++) {
        tmp&#91;i] = sbox&#91;tmp&#91;i]];
    }
}// subbytes

uchar myAES::mix(uchar byte, unsigned int mixvalue) {
    unsigned char retValue;
    switch (mixvalue) {
        case 1:
            retValue = byte;
            break;
        case 2:
            retValue = byte &lt;&lt; 1;
            if (byte &amp; 0x80) {
                retValue = retValue ^ 0x1b;
            }
            break;
        case 3:
            retValue = byte &lt;&lt; 1;
            if (byte &amp; 0x80) {
                retValue = retValue ^ 0x1b;
            }
            retValue = retValue^byte;
            break;
    }
    return retValue;
}

void addRoundKey(uchar array&#91;], uchar matrix&#91;]&#91;44], int iReihe, int iSpalte, int iRunde) {
    int pos = 0;
    for (int i = iRunde * 4; i &lt; ((iRunde * 4) + 4) &amp;&amp; i &lt; iSpalte; i++) {
        for (int k = 0; k &lt; iReihe; k++) {
            array&#91;pos] = array&#91;pos] ^ matrix&#91;k]&#91;i];
            pos++;
        }
    }
}// addroundkey

void myAES::rotword(uchar column&#91;], int iReihe) {
    uchar tmp = column&#91;0];
    for (int i = 1; i &lt; iReihe; i++) {
        column&#91;i - 1] = column&#91;i];
    }
    column&#91;iReihe - 1] = tmp;
} // rotword

void myAES::schluesselexpansion(uchar matrix&#91;]&#91;44], int iReihe, int iSpalte, int iLaenge) {
    // Alle Spalten durchlaufen
    int pos = 0;

    for (int i = 0; i &lt; iSpalte; i++) {
        if (i &lt; 4) { // Schluessel in erste vier Spalten kopieren
            for (int k = 0; k &lt; iReihe &amp;&amp; pos &lt; iLaenge; k++) {
                matrix&#91;k]&#91;i] = schluessel&#91;pos];
                pos++;
                //cout &lt;&lt; hex &lt;&lt; "matrix&#91;" &lt;&lt; k &lt;&lt; "]&#91;" &lt;&lt; i &lt;&lt; "] = " &lt;&lt; (int) matrix&#91;k]&#91;i] &lt;&lt; endl;
            }
        } else { // i &gt; 4
            if (i % 4 == 0) {// erste Spalte eines Schluessels
                // Spalte in Hilfsarray kopieren
                uchar tmp&#91;iReihe]; // i-1
                uchar tmp2&#91;iReihe]; // i-4
                for (int k = 0; k &lt; iReihe; k++) {
                    tmp&#91;k] = matrix&#91;k]&#91;i - 1];
                    tmp2&#91;k] = matrix&#91;k]&#91;i - 4];
                }

                rotword(tmp, iReihe);

                subbytes(Sbox, tmp, iReihe);

                // Spalte&#91;i-4] XOR subbytes&#91;rotword&#91;i-i]
                for (int k = 0; k &lt; iReihe; k++) {
                    tmp&#91;k] = tmp&#91;k] ^ tmp2&#91;k];
                }

                // tmp&#91;0] XOR (i/4)
                tmp&#91;0] = tmp&#91;0] ^ Rcon&#91;i / iReihe];

                // tmp&#91;k] an Spalte&#91;k]&#91;i] kopieren
                for (int k = 0; k &lt; iReihe; k++) {
                    matrix&#91;k]&#91;i] = tmp&#91;k];
                }

            } else {
                //cout &lt;&lt; "i " &lt;&lt; i &lt;&lt; endl;
                for (int k = 0; k &lt; iReihe; k++) {
                    matrix&#91;k]&#91;i] = matrix&#91;k]&#91;i - 4] ^ matrix&#91;k]&#91;i - 1];
                }
            }
        }
    }
}// schluesselexpansion

void myAES::shiftrows() {
    uchar copys&#91;16] = {};

    //reihe 1   
    copys&#91;0] = ciphertext&#91;0];
    copys&#91;4] = ciphertext&#91;4];
    copys&#91;8] = ciphertext&#91;8];
    copys&#91;12] = ciphertext&#91;12];

    //reihe 2
    copys&#91;1] = ciphertext&#91;5];
    copys&#91;5] = ciphertext&#91;9];
    copys&#91;9] = ciphertext&#91;13];
    copys&#91;13] = ciphertext&#91;1];

    // reihe 3
    copys&#91;2] = ciphertext&#91;10];
    copys&#91;6] = ciphertext&#91;14];
    copys&#91;10] = ciphertext&#91;2];
    copys&#91;14] = ciphertext&#91;6];

    //reihe 4
    copys&#91;3] = ciphertext&#91;15];
    copys&#91;7] = ciphertext&#91;3];
    copys&#91;11] = ciphertext&#91;7];
    copys&#91;15] = ciphertext&#91;11];

    //umschreiben   
    for (int i = 0; i &lt; 16; i++) {
        ciphertext&#91;i] = copys&#91;i];
    }
}// shiftrows

void myAES::mixcolumns() {
    for (int i = 0; i &lt; 4; i++) {
        uchar sj0 = mix(ciphertext&#91;i * 4], 2)^mix(ciphertext&#91;i * 4 + 1], 3)^mix(ciphertext&#91;i * 4 + 2], 1)^mix(ciphertext&#91;i * 4 + 3], 1);
        uchar sj1 = mix(ciphertext&#91;i * 4], 1)^mix(ciphertext&#91;i * 4 + 1], 2)^mix(ciphertext&#91;i * 4 + 2], 3)^mix(ciphertext&#91;i * 4 + 3], 1);
        uchar sj2 = mix(ciphertext&#91;i * 4], 1)^mix(ciphertext&#91;i * 4 + 1], 1)^mix(ciphertext&#91;i * 4 + 2], 2)^mix(ciphertext&#91;i * 4 + 3], 3);
        uchar sj3 = mix(ciphertext&#91;i * 4], 3)^mix(ciphertext&#91;i * 4 + 1], 1)^mix(ciphertext&#91;i * 4 + 2], 1)^mix(ciphertext&#91;i * 4 + 3], 2);
        ciphertext&#91;i * 4] = sj0;
        ciphertext&#91;i * 4 + 1] = sj1;
        ciphertext&#91;i * 4 + 2] = sj2;
        ciphertext&#91;i * 4 + 3] = sj3;
    }
}// mixcolumns

void myAES::crypt(bool output) {

    // Parameter
    int iRunde = 10;
    int iLaenge = 16;

    // Überschreibe ciphertext um diesen fortan zu verwenden
    for (int i = 0; i &lt; 16; i++) {
        ciphertext&#91;i] = klartext&#91;i];
    }

    // Arraygroesse dynamisch bestimmen
    int arrSize = sizeof (ciphertext) / sizeof (ciphertext&#91;0]);

    // Zwischenspeicherung der Rundenschluessel
    int iReihe = 4;
    int iSpalte = 4 * (iRunde + 1);
    uchar carrRundenschluessel&#91;4]&#91;44];

    // Schluessel expandieren
    schluesselexpansion(carrRundenschluessel, iReihe, iSpalte, iLaenge);

    // Vorrunde
    for (int k = 0; k &lt; iLaenge; k++) {
        ciphertext&#91;k] = ciphertext&#91;k] ^ schluessel&#91;k];
    }

    // Durchlaufen der Runden
    for (int i = 1; i &lt; iRunde + 1; i++) {

        // S-Box
        subbytes(Sbox, ciphertext, arrSize);

        // Shift Rows
        shiftrows();

        // Mix Columns
        if (i != (iRunde)) { // kein MixColumns in der letzten Runde
            mixcolumns();
        }

        // Rundenschlüssel addieren
        addRoundKey(ciphertext, carrRundenschluessel, iReihe, iSpalte, i);

    }
}

void myAES::invert_shiftrows() {
    uchar copys&#91;16] = {};

    //reihe 1   
    copys&#91;0] = klartext&#91;0];
    copys&#91;4] = klartext&#91;4];
    copys&#91;8] = klartext&#91;8];
    copys&#91;12] = klartext&#91;12];

    //reihe 2
    copys&#91;1] = klartext&#91;13];
    copys&#91;13] = klartext&#91;9];
    copys&#91;9] = klartext&#91;5];
    copys&#91;5] = klartext&#91;1];

    // reihe 3   
    copys&#91;6] = klartext&#91;14];
    copys&#91;2] = klartext&#91;10];
    copys&#91;14] = klartext&#91;6];
    copys&#91;10] = klartext&#91;2];

    //reihe 4
    copys&#91;11] = klartext&#91;15];
    copys&#91;7] = klartext&#91;11];
    copys&#91;3] = klartext&#91;7];
    copys&#91;15] = klartext&#91;3];

    //umschreiben   
    for (int i = 0; i &lt; 16; i++) {
        klartext&#91;i] = copys&#91;i];
    }
}// invert_shiftrows

void myAES::invert_mixcolumns() {
    for (int i = 0; i &lt; 4; i++) {
        uchar sj0 = gmul(klartext&#91;i * 4], 14)^gmul(klartext&#91;i * 4 + 1], 11)^gmul(klartext&#91;i * 4 + 2], 13)^gmul(klartext&#91;i * 4 + 3], 9);
        uchar sj1 = gmul(klartext&#91;i * 4], 9)^gmul(klartext&#91;i * 4 + 1], 14)^gmul(klartext&#91;i * 4 + 2], 11)^gmul(klartext&#91;i * 4 + 3], 13);
        uchar sj2 = gmul(klartext&#91;i * 4], 13)^gmul(klartext&#91;i * 4 + 1], 9)^gmul(klartext&#91;i * 4 + 2], 14)^gmul(klartext&#91;i * 4 + 3], 11);
        uchar sj3 = gmul(klartext&#91;i * 4], 11)^gmul(klartext&#91;i * 4 + 1], 13)^gmul(klartext&#91;i * 4 + 2], 9)^gmul(klartext&#91;i * 4 + 3], 14);
        klartext&#91;i * 4] = sj0;
        klartext&#91;i * 4 + 1] = sj1;
        klartext&#91;i * 4 + 2] = sj2;
        klartext&#91;i * 4 + 3] = sj3;
    }
}

uchar myAES::gmul(uchar a, uchar b) {
    unsigned char p = 0;
    unsigned char hi;

    for (int i = 0; i &lt; 8; ++i) {
        if ((b &amp; 1) == 1)
            p ^= a;
        hi = (a &amp; 0x80);
        a &lt;&lt;= 1;
        if (hi == 0x80)
            a ^= 0x1b;
        b &gt;&gt;= 1;
    }
    return p;
}

void myAES::decrypt(bool output) {

    // Parameter
    int iRunde = 10;
    int iLaenge = 16;


    // Überschreibe klartext um diesen fortan zu verwenden
    for (int i = 0; i &lt; 16; i++) {
        klartext&#91;i] = ciphertext&#91;i];
    }

    // Arraygroesse dynamisch bestimmen
    int arrSize = sizeof (klartext) / sizeof (klartext&#91;0]);

    // Zwischenspeicherung der Rundenschluessel
    int iReihe = 4;
    int iSpalte = 4 * (iRunde + 1);
    uchar carrRundenschluessel&#91;4]&#91;44];

    // Schluessel expandieren
    schluesselexpansion(carrRundenschluessel, iReihe, iSpalte, iLaenge);

    // "neue" Vorrunde
    addRoundKey(klartext, carrRundenschluessel, iReihe, iSpalte, 10);

    // Durchlaufen der Runden
    for (int i = 9; i &gt; 0; i--) {

        // Shift Rows
        invert_shiftrows();

        // S-Box
        subbytes(sbox_inverse, klartext, arrSize);

        // Rundenschlüssel addieren
        addRoundKey(klartext, carrRundenschluessel, iReihe, iSpalte, i);

        // Mix Columns
        if (i != 10) { // kein MixColumns in der letzten Runde
            invert_mixcolumns();
        }
    }

    // Letzte Runde
    invert_shiftrows();
    subbytes(sbox_inverse, klartext, arrSize);

    for (int k = 0; k &lt; iLaenge; k++) {
        klartext&#91;k] = klartext&#91;k] ^ schluessel&#91;k];
    }
}// decrypt

//&lt;/editor-fold&gt;

//&lt;editor-fold defaultstate="collapsed" desc="Konstruktur/Destruktor"&gt;

myAES::myAES() {
    uchar kt&#91;16] = {0x61, 0x62, 0x62, 0x69, 0x6c, 0x64, 0x75, 0x6e, 0x67, 0x73, 0x6d, 0x61, 0x74, 0x72, 0x69, 0x78};
    uchar s&#91;16] = {0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31};
    //uchar c&#91;16] = {0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31};
    for (int i = 0; i &lt; 16; i++) {
        schluessel&#91;i] = s&#91;i];
        klartext&#91;i] = kt&#91;i];
    }
}

myAES::~myAES() {
}
//&lt;/editor-fold&gt;

//&lt;editor-fold defaultstate="collapsed" desc="Manuelle Eingabe"&gt;

void enterValues(uchar arr&#91;], string name) {
    string tmp = "";
    int diff = 0;
    cout &lt;&lt; name &lt;&lt; ": (16 Zeichen):";
    if (cin &gt;&gt; tmp) {

        if (tmp.length() &gt; 16) {
            cerr &lt;&lt; "\nWerte fuer den" &lt;&lt; name &lt;&lt; " zu groß. Trenne nach 16 Zeichen ab.\n(";
            for (int i = 0; i &lt; tmp.length(); i++) {
                if (i == 16) {
                    cerr &lt;&lt; " | ";
                }
                cerr &lt;&lt; tmp.at(i);
            }
            cout &lt;&lt; ")" &lt;&lt; endl;
        }

        if (tmp.length() &lt; 16) {
            cerr &lt;&lt; "\nWert fuer den Klartext zu klein. Fuelle mit Nullen auf.\n";
            diff = 16 - tmp.length();
            for (int i = 0; i &lt; diff; i++) {
                tmp.push_back('\0');
            }
            cout &lt;&lt; endl;
        }

        for (int i = 0; i &lt; 16; i++) {
            arr&#91;i] = tmp&#91;i];
        }
        cout &lt;&lt; endl;

    }
}

void myAES::enterKlartext() {
    enterValues(klartext, "Klartext");
}

void myAES::enterSchluessel() {
    enterValues(schluessel, "Schluessel");
}

//&lt;/editor-fold&gt;

//&lt;editor-fold defaultstate="collapsed" desc="Set/Get-Methoden"&gt;

void myAES::setCiphertext(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        ciphertext&#91;i] = tmp&#91;i];
    }
}

void myAES::setKlartext(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        klartext&#91;i] = tmp&#91;i];
    }
}

void myAES::setSchluessel(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        schluessel&#91;i] = tmp&#91;i];
    }
}

uchar* myAES::getSchluessel() {
    return schluessel;
}

uchar* myAES::getCiphertext() {
    return ciphertext;
}

uchar* myAES::getKlartext() {
    return klartext;
}

//&lt;/editor-fold&gt;
</code></pre>



<h3 class="wp-block-heading">myCBC.h</h3>



<pre class="wp-block-code"><code>
#ifndef MYCBC_H
#define	MYCBC_H
#include "myAES.h"
#include &lt;vector&gt;
class myCBC {
public:
    // Konstruktoren / Destruktoren
    myCBC();
    virtual ~myCBC();
    
    //CBC
    void crypt(bool);
    void decrypt(bool);
    
    // Set/Get-Methoden
    void setKey(uchar&#91;16]);
    void setIV(uchar&#91;16]);
    void setKlartext(vector&lt;uchar&gt;);
    void setCiphertext(vector&lt;uchar&gt;);
    vector&lt;uchar&gt; getKlartext();
    vector&lt;uchar&gt; getCiphertext();
    uchar* getSchluessel();
    uchar* getIV();
    
    // Manuelle Eingabe
    void enterKey();
    void enterIV();
    void enterKlartext();
    
private:
    uchar iv&#91;16];
    uchar key&#91;16];
    vector&lt;uchar&gt; klartext;
    vector&lt;uchar&gt; ciphertext;
};
</code></pre>



<h3 class="wp-block-heading">myCBC.cpp</h3>



<pre class="wp-block-code"><code>
#include "myCBC.h"
#include &lt;math.h&gt;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;

using namespace std;

uchar* myCBC::getSchluessel() {
    return key;
}

vector&lt;uchar&gt; myCBC::getKlartext() {
    return klartext;
}

void enterValue(uchar arr&#91;], string name) {
    string tmp = "";
    int diff = 0;
    cout &lt;&lt; name &lt;&lt; ": (16 Zeichen):";
    if (cin &gt;&gt; tmp) {

        if (tmp.length() &gt; 16) {
            cerr &lt;&lt; "\nWerte fuer den" &lt;&lt; name &lt;&lt; " zu groß. Trenne nach 16 Zeichen ab.\n(";
            for (int i = 0; i &lt; tmp.length(); i++) {
                if (i == 16) {
                    cerr &lt;&lt; " | ";
                }
                cerr &lt;&lt; tmp.at(i);
            }
            cout &lt;&lt; ")" &lt;&lt; endl;
        }

        if (tmp.length() &lt; 16) {
            cerr &lt;&lt; "\nWert fuer den Klartext zu klein. Fuelle mit Nullen auf.\n";
            diff = 16 - tmp.length();
            for (int i = 0; i &lt; diff; i++) {
                tmp.push_back('\0');
            }
            cout &lt;&lt; endl;
        }

        for (int i = 0; i &lt; 16; i++) {
            arr&#91;i] = tmp&#91;i];
        }
        cout &lt;&lt; endl;

    }
}

void myCBC::enterKey() {
    enterValue(key, "Schluessel");
}

void myCBC::enterIV() {
    enterValue(iv, "Initialisierungsvektor");
}

void myCBC::enterKlartext() {
    klartext.clear();
    string tmp = "";
    cout &lt;&lt; "Klartext (Beliebig viele Zeichen):";
    if (cin &gt;&gt; tmp) {
        for (int i = 0; i &lt; tmp.size(); i++) {
            klartext.push_back(tmp&#91;i]);
        }
        cout &lt;&lt; endl;
    }

    if (tmp.size() % 16 != 0) {
        cerr &lt;&lt; "\nLetzter Klartext-Block nicht vollstaendig. Fuelle mit Nullen auf.\n";
        for (int i = 0; i &lt; 16 - tmp.size() % 16; i++) {
            klartext.push_back('\0');
        }
        cout &lt;&lt; endl;
    }
}

myCBC::myCBC() {

    // Default Parameter
    uchar newKey&#91;16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
    uchar newIV&#91;16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
    uchar newKlartext&#91;16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};

    // Schluessel setzen
    for (int i = 0; i &lt; 16; i++) {
        key&#91;i] = newKey&#91;i];
    }

    //IV setzen
    for (int i = 0; i &lt; 16; i++) {
        iv&#91;i] = newIV&#91;i];
    }

    // Klartext setzen
    for (int i = 0; i &lt; 16; i++) {
        klartext.push_back(newKlartext&#91;i]);
    }
}

vector&lt;uchar&gt; myCBC::getCiphertext() {
    return ciphertext;
}

void myCBC::decrypt(bool print) {
    klartext.clear();

    uchar tmp_iv&#91;16];
    for (int j = 0; j &lt; 16; j++) {
        tmp_iv&#91;j] = iv&#91;j];
    }
    for (int i = 0; i &lt; ciphertext.size() / 16; i++) {

        myAES a1;

        //Übergabe - Array
        uchar tmp&#91;16];
        for (int k = 0; k &lt; 16; k++) {
            tmp&#91;k] = ciphertext&#91;k + 16 * i];
        }

        // Ciphertext
        a1.setCiphertext(tmp);

        // Schluessel
        a1.setSchluessel(key);

        // decrypt
        a1.decrypt(false);

        // Resultat mit IV addieren / XOR
        for (int f = 0; f &lt; 16; f++) {
            a1.getKlartext()&#91;f] = a1.getKlartext()&#91;f]^tmp_iv&#91;f];
        }

        // Neuen IV festlegen und Klartext eintragen
        for (int l = 0; l &lt; 16; l++) {
            tmp_iv&#91;l] = a1.getCiphertext()&#91;l];
            klartext.push_back(a1.getKlartext()&#91;l]);
        }
    }
}

void myCBC::crypt(bool print) {
    ciphertext.clear();
    uchar tmp_iv&#91;16];
    for (int i = 0; i &lt; 16; i++) {
        tmp_iv&#91;i] = iv&#91;i];
    }

    for (int i = 0; i &lt; klartext.size() / 16; i++) {

        myAES a1;
        a1.setSchluessel(key);

        //XOR in Übergabe - Array
        uchar tmp&#91;16];
        for (int j = 0; j &lt; 16; j++) {
            tmp&#91;j] = klartext&#91;j + 16 * i]^tmp_iv&#91;j];
        }

        // Klartext
        a1.setKlartext(tmp);

        // crypt
        a1.crypt(false);


        for (int j = 0; j &lt; 16; j++) {
            tmp_iv&#91;j] = a1.getCiphertext()&#91;j];
            ciphertext.push_back(a1.getCiphertext()&#91;j]);
        }
    }
}

void myCBC::setKlartext(vector&lt;uchar&gt; kt) {
    // Padding mit 0
    if (kt.size() &gt; klartext.size()) {
        int diff = kt.size() - klartext.size();
        for (int i = 0; i &lt; diff; i++) {
            klartext.push_back(0x00);
        }
    }

    // Werte übertragen
    for (int i = 0; i &lt; kt.size(); i++) {
        klartext.at(i) = kt.at(i);
    }
}

void myCBC::setIV(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        iv&#91;i] = tmp&#91;i];
    }
}

void myCBC::setKey(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        key&#91;i] = tmp&#91;i];
    }
}

myCBC::~myCBC() {
}
</code></pre>



<h3 class="wp-block-heading">myECB.h</h3>



<pre class="wp-block-code"><code>
#ifndef MYECB_H
#define	MYECB_H

#include "myAES.h"
#include &lt;vector&gt;
class myECB {
public:
    // Konstruktoren / Destruktoren
    myECB();
    virtual ~myECB();
    
    //CBC
    void crypt(bool);
    void decrypt(bool);
    
    // Set/Get-Methoden
    void setKey(uchar&#91;16]);
    void setKlartext(vector&lt;uchar&gt;);
    void setCiphertext(vector&lt;uchar&gt;);
    vector&lt;uchar&gt; getKlartext();
    vector&lt;uchar&gt; getCiphertext();
    uchar* getSchluessel();
    
    // Manuelle Eingabe
    void enterKey();    
    void enterKlartext();

private:
    uchar key&#91;16];
    vector&lt;uchar&gt; klartext;
    vector&lt;uchar&gt; ciphertext;

};

#endif	/* MYECB_H */
</code></pre>



<h3 class="wp-block-heading">myECB.cpp</h3>



<pre class="wp-block-code"><code>
#include "myECB.h"
#include &lt;iomanip&gt;
#include &lt;iostream&gt;

void myECB::enterKey() {
    string tmp = "";
    int diff = 0;
    cout &lt;&lt; "Schluessel (16 Zeichen):";
    if (cin &gt;&gt; tmp) {

        if (tmp.length() &gt; 16) {
            cerr &lt;&lt; "\nWerte fuer den Schluessel zu groß. Trenne nach 16 Zeichen ab.\n(";
            for (int i = 0; i &lt; tmp.length(); i++) {
                if (i == 16) {
                    cerr &lt;&lt; " | ";
                }
                cerr &lt;&lt; tmp.at(i);
            }
            cout &lt;&lt; ")" &lt;&lt; endl;
        }

        if (tmp.length() &lt; 16) {
            cerr &lt;&lt; "\nWert fuer den Klartext zu klein. Fuelle mit Nullen auf.\n";
            diff = 16 - tmp.length();
            for (int i = 0; i &lt; diff; i++) {
                tmp.push_back('\0');
            }
            cout &lt;&lt; endl;
        }

        for (int i = 0; i &lt; 16; i++) {
            key&#91;i] = tmp&#91;i];
        }
        cout &lt;&lt; endl;
    }
}

vector&lt;uchar&gt; myECB::getKlartext() {
    return klartext;
}

void myECB::enterKlartext() {
    klartext.clear();
    string tmp = "";
    cout &lt;&lt; "Klartext (Beliebig viele Zeichen):";
    if (cin &gt;&gt; tmp) {
        for (int i = 0; i &lt; tmp.size(); i++) {
            klartext.push_back(tmp&#91;i]);
        }
        cout &lt;&lt; endl;
    }

    if (tmp.size() % 16 != 0) {
        cerr &lt;&lt; "\nLetzter Klartext-Block nicht vollstaendig. Fuelle mit Nullen auf.\n";
        for (int i = 0; i &lt; 16 - tmp.size() % 16; i++) {
            klartext.push_back('\0');
        }
        cout &lt;&lt; endl;
    }
}

myECB::myECB() {

    // Default Parameter
    uchar newKey&#91;16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
    uchar newKlartext&#91;16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};

    // Schluessel setzen
    for (int i = 0; i &lt; 16; i++) {
        key&#91;i] = newKey&#91;i];
    }

    // Klartext setzen
    for (int i = 0; i &lt; 16; i++) {
        klartext.push_back(newKlartext&#91;i]);
    }
}

vector&lt;uchar&gt; myECB::getCiphertext() {
    return ciphertext;
}

void myECB::decrypt(bool print) {
    klartext.clear();

    for (int i = 0; i &lt; ciphertext.size() / 16; i++) {

        myAES a1;

        //Übergabe - Array
        uchar tmp&#91;16];
        for (int j = 0; j &lt; 16; j++) {
            tmp&#91;j] = ciphertext&#91;j + 16 * i];
        }

        // Ciphertext
        a1.setCiphertext(tmp);

        // Schluessel
        a1.setSchluessel(key);

        // crypt
        a1.decrypt(false);

        // Resultat mit IV addieren
        for (int j = 0; j &lt; 16; j++) {
            klartext.push_back(a1.getKlartext()&#91;j]);
        }
    }
}

void myECB::crypt(bool print) {
    ciphertext.clear();

    for (int i = 0; i &lt; klartext.size() / 16; i++) {

        myAES a1;
        a1.setSchluessel(key);

        //XOR in Übergabe - Array
        uchar tmp&#91;16];
        for (int j = 0; j &lt; 16; j++) {
            tmp&#91;j] = klartext&#91;j + 16 * i]; //^tmp_iv&#91;j];
        }

        // Klartext
        a1.setKlartext(tmp);

        // crypt
        a1.crypt(false);


        for (int j = 0; j &lt; 16; j++) {
            ciphertext.push_back(a1.getCiphertext()&#91;j]);
        }
    }
}

void myECB::setKlartext(vector&lt;uchar&gt; kt) {
    if (kt.size() &gt; klartext.size()) {
        int diff = kt.size() - klartext.size();
        for (int i = 0; i &lt; diff; i++) {
            klartext.push_back(0x00);
        }
    }
    for (int i = 0; i &lt; kt.size(); i++) {
        klartext.at(i) = kt.at(i);
    }
}

void myECB::setKey(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        key&#91;i] = tmp&#91;i];
    }
}

myECB::~myECB() {
}
</code></pre>



<h3 class="wp-block-heading">myGUI.h</h3>



<pre class="wp-block-code"><code>
#ifndef MYGUI_H
#define	MYGUI_H

#include &lt;iostream&gt;
#include "myCBC.h"
#include "myECB.h"

class myGUI {
public:
    // Menu
    myGUI();
    void menuAES();
    void menuCBC();
    void menuECB();
    // Tests
    bool checkAES();
    bool checkCBC();
    bool checkECB();
    virtual ~myGUI();
private:
};

#endif	/* MYGUI_H */
</code></pre>



<h3 class="wp-block-heading">myGUI.cpp</h3>



<pre class="wp-block-code"><code>
//Präprozessor-Direktiven
#include "support.h"
#include "myGUI.h"
#include &lt;vector&gt;
#include &lt;iostream&gt;
#include  &lt;iomanip&gt;


//Namensbereich Auflösung
using namespace std;

// &lt;editor-fold defaultstate="collapsed" desc="Methoden bzgl. AES"&gt;

bool myGUI::checkAES() {

    bool returnValue = false;

    // Testvektoren
    uchar schluessel&#91;16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
    uchar klartext_1&#91;16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
    uchar klartext_2&#91;16] = {0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51};
    uchar klartext_3&#91;16] = {0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef};
    uchar cipher_1&#91;16] = {0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60, 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97};
    uchar cipher_2&#91;16] = {0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d, 0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf};
    uchar cipher_3&#91;16] = {0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23, 0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88};

    // Test#1
    myAES aes1;
    aes1.setKlartext(klartext_1);
    aes1.setSchluessel(schluessel);
    aes1.crypt(false);

    // Test#2
    myAES aes2;
    aes2.setKlartext(klartext_2);
    aes2.setSchluessel(schluessel);
    aes2.crypt(false);

    // Test#3
    myAES aes3;
    aes3.setKlartext(klartext_3);
    aes3.setSchluessel(schluessel);
    aes3.crypt(false);

    // Prüfung
    bool isWorking = areEqual(aes3.getCiphertext(), cipher_3) &amp;&amp; areEqual(aes2.getCiphertext(), cipher_2) &amp;&amp; areEqual(aes1.getCiphertext(), cipher_1);
    if (isWorking) {
        returnValue = true;
    } else {

        returnValue = false;
    }
    return returnValue;
}

void myGUI::menuAES() {

    // Variablen initialisieren
    bool run = true;
    unsigned int lowest = 1;
    unsigned int end = 4;
    int input = end;

    // aes initialisieren und verschlüsseln
    myAES aes;
    aes.crypt(false);

    //Menu Eingabe
    while (run) {
        cout &lt;&lt; "\nBitte waehlen sie aus:\n";
        cout &lt;&lt; "(1) Text verschluesseln \n";
        cout &lt;&lt; "(2) Text und Schluessel eingeben \n";
        cout &lt;&lt; "(3) Text entschluesseln \n";
        cout &lt;&lt; "(4) Zurueck\n";
        cout &lt;&lt; "&gt; ";

        // Eingabe überprüfen
        input = validatedInput(lowest, end);

        // Auswahl
        if (input == 1) {
            aes.crypt(true);
            printMatrix(aes.getKlartext(), "Klartext");
            printMatrix(aes.getSchluessel(), "Schluessel");
            printMatrix(aes.getCiphertext(), "Cipher");
        }
        if (input == 2) {
            aes.enterKlartext();
            aes.enterSchluessel();
            aes.crypt(true);
            printMatrix(aes.getKlartext(), "Klartext");
            printMatrix(aes.getSchluessel(), "Schluessel");
            printMatrix(aes.getCiphertext(), "Cipher");
        }
        if (input == 3) {
            aes.decrypt(true);
            printMatrix(aes.getCiphertext(), "Cipher");
            printMatrix(aes.getSchluessel(), "Schluessel");
            printMatrix(aes.getKlartext(), "Klartext");
        }
        if (input == end) {
            run = false;
        }
        if (input == -1) {

            cerr &lt;&lt; "Ungueltige Eingabe getätigt.\nBitte nochmal eingeben.\n";
            cout &lt;&lt; endl;
        }
    }
}

// &lt;/editor-fold&gt;

// &lt;editor-fold defaultstate="collapsed" desc="Methoden bzgl. CBC"&gt;

bool myGUI::checkCBC() {
    bool returnValue = false;

    // Test #1  - 16 Byte Testvektoren
    uchar keyB&#91;16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
    uchar ivB&#91;16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
    uchar klartextB1&#91;16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
    uchar ciphertextB1&#91;16] = {0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d};

    // Container 
    vector&lt;uchar&gt; cipherB1;
    vector&lt;uchar&gt; ktB;

    // Container füllen
    for (int i = 0; i &lt; 16; i++) {
        ktB.push_back(klartextB1&#91;i]);
        cipherB1.push_back(ciphertextB1&#91;i]);
    }

    // cbc intialisieren
    myCBC cbcB;
    cbcB.setKey(keyB);
    cbcB.setIV(ivB);
    cbcB.setKlartext(ktB);

    // Verschlüsseln
    cbcB.crypt(false);

    // Test#2 - 32 Byte Testvektoren
    uchar klartextA1&#91;16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
    uchar klartextA2&#91;16] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f};
    uchar ivA&#91;16] = {0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28, 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58};
    uchar keyA&#91;16] = {0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0, 0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a};
    uchar ciphertextA1&#91;16] = {0xd2, 0x96, 0xcd, 0x94, 0xc2, 0xcc, 0xcf, 0x8a, 0x3a, 0x86, 0x30, 0x28, 0xb5, 0xe1, 0xdc, 0x0a};
    uchar ciphertextA2&#91;16] = {0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9, 0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1};

    // Container
    vector&lt;uchar&gt; cipherA1;
    vector&lt;uchar&gt; test;

    // Container füllen
    for (int i = 0; i &lt; 16; i++) {
        test.push_back(klartextA1&#91;i]);
        cipherA1.push_back(ciphertextA1&#91;i]);
    }

    for (int i = 0; i &lt; 16; i++) {
        test.push_back(klartextA2&#91;i]);
        cipherA1.push_back(ciphertextA2&#91;i]);
    }

    // cbc initialisieren
    myCBC cbcA;
    cbcA.setKey(keyA);
    cbcA.setIV(ivA);
    cbcA.setKlartext(test);

    // Verschlüsseln
    cbcA.crypt(false);

    //Prüfung auf Korrektheit
    bool isWorking = areEqual(cbcA.getCiphertext(), cipherA1) &amp;&amp; areEqual(cbcB.getCiphertext(), cipherB1);

    if (isWorking) {
        returnValue = true;
    } else {
        returnValue = false;
    }
    return returnValue;
}

void myGUI::menuCBC() {

    // cbc mit Standard Werten initialisieren
    myCBC cbc;
    cbc.crypt(false);

    // Variablen initialisieren
    bool run = true;
    unsigned int lowest = 1;
    unsigned int end = 5;
    int input = end;

    //Menu Eingabe
    while (run) {
        cout &lt;&lt; "\nBitte waehlen sie aus:\n";
        cout &lt;&lt; "(1) Text verschluesseln \n";
        cout &lt;&lt; "(2) Text und Schluessel eingeben \n";
        cout &lt;&lt; "(3) Bild ver- und entschluesseln\n";
        cout &lt;&lt; "(4) Text entschluesseln\n";
        cout &lt;&lt; "(5) Zurueck\n";
        cout &lt;&lt; "&gt; ";

        // Überprüfe Eingabe
        input = validatedInput(lowest, end);

        // Auswahl
        if (input == 1) {
            cbc.crypt(true);
            printMatrix(cbc.getKlartext(), "Klartext");
            printMatrix(cbc.getSchluessel(), "Schluessel");
            printMatrix(cbc.getCiphertext(), "Cipher");
        }
        if (input == 2) {
            cbc.enterIV();
            cbc.enterKey();
            cbc.enterKlartext();
            cbc.crypt(true);
            printMatrix(cbc.getKlartext(), "Klartext");
            printMatrix(cbc.getSchluessel(), "Schluessel");
            printMatrix(cbc.getCiphertext(), "Cipher");
        }
        if (input == 3) {
            //Fülle Vektor mit Punkten
            vector&lt;uchar&gt; myImg;
            fillImage(myImg);

            // Gebe Klartext aus
            printImage(myImg);

            // Setze Klartext, verschlüssle und gebe Cipher aus
            cbc.setKlartext(myImg);
            cbc.crypt(false);
            printImage(cbc.getCiphertext());

            // Entschlüssle und gebe Klartext aus
            cbc.decrypt(false);
            printImage(cbc.getKlartext());
        }
        if (input == 4) {
            cbc.decrypt(true);
            printMatrix(cbc.getCiphertext(), "Cipher");
            printMatrix(cbc.getSchluessel(), "Schluessel");
            printMatrix(cbc.getKlartext(), "Klartext");
        }
        if (input == end) {
            run = false;
        }
        if (input == -1) {
            cerr &lt;&lt; "Ungueltige Eingabe getätigt.\nBitte nochmal eingeben.\n";
            cout &lt;&lt; endl;
        }
    }

}

// &lt;/editor-fold&gt;

// &lt;editor-fold defaultstate="collapsed" desc="Methoden bzgl. ECB"&gt;

bool myGUI::checkECB() {
    bool returnValue = false;

    //16 Byte Testvektoren
    uchar schluessel&#91;16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};

    uchar klartext_1&#91;16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
    uchar klartext_2&#91;16] = {0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51};
    uchar klartext_3&#91;16] = {0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef};

    uchar cipher_1&#91;16] = {0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60, 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97};
    uchar cipher_2&#91;16] = {0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d, 0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf};
    uchar cipher_3&#91;16] = {0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23, 0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88};

    // Container
    vector&lt;uchar&gt; cipherB1;
    vector&lt;uchar&gt; ktB;

    // Fülle Container mit Block 1
    for (int i = 0; i &lt; 16; i++) {
        ktB.push_back(klartext_1&#91;i]);
        cipherB1.push_back(cipher_1&#91;i]);
    }

    // Fülle Container mit Block 2
    for (int i = 0; i &lt; 16; i++) {
        ktB.push_back(klartext_2&#91;i]);
        cipherB1.push_back(cipher_2&#91;i]);
    }

    // Fülle Container mit Block 3
    for (int i = 0; i &lt; 16; i++) {
        ktB.push_back(klartext_3&#91;i]);
        cipherB1.push_back(cipher_3&#91;i]);
    }

    // Verschlüssele mit Hilfe des Schlüssels und den 3 Blöcken
    myECB ecb;
    ecb.setKey(schluessel);
    ecb.setKlartext(ktB);
    ecb.crypt(false);

    //Prüfung auf Gleichheit
    bool isWorking = areEqual(ecb.getCiphertext(), cipherB1);
    if (isWorking) {
        returnValue = true;
    } else {
        returnValue = false;
    }
    return returnValue;
}

void myGUI::menuECB() {


    //Initialisiere ecb mit Standard-Werten
    myECB ecb;
    ecb.crypt(false);

    //Initialisiere Eingabe-Variablen 
    bool run = true;
    unsigned int lowest = 1;
    unsigned int end = 5;
    int input = end;

    //Menu Eingabe
    while (run) {

        cout &lt;&lt; "\nBitte waehlen sie aus:\n";
        cout &lt;&lt; "(1) Text verschluesseln \n";
        cout &lt;&lt; "(2) Text und Schluessel eingeben \n";
        cout &lt;&lt; "(3) Bild ver- und entschluesseln\n";
        cout &lt;&lt; "(4) Text entschluesseln\n";
        cout &lt;&lt; "(5) Zurueck\n";
        cout &lt;&lt; "&gt; ";

        // Prüfe Eingabe
        input = validatedInput(lowest, end);

        // Auswahl
        if (input == 1) {
            ecb.crypt(true);
        }
        if (input == 2) {
            ecb.enterKey();
            ecb.enterKlartext();
            ecb.crypt(true);
        }
        if (input == 3) {
            // Erstelle Vektor mit Bildpunkten
            vector&lt;uchar&gt; myImg;
            fillImage(myImg);

            // Gebe Klartext aus
            printImage(myImg);
            ecb.setKlartext(myImg);

            // Verschlpsseln und Gebe Cipher aus
            ecb.crypt(false);
            printImage(ecb.getCiphertext());

            // Entschlüsseln und Klartext ausgeben
            ecb.decrypt(false);
            printImage(ecb.getKlartext());
        }
        if (input == 4) {
            ecb.decrypt(true);
        }
        if (input == end) {
            run = false;
        }
        if (input == -1) {
            cerr &lt;&lt; "Ungueltige Eingabe getätigt.\nBitte nochmal eingeben.\n";
            cout &lt;&lt; endl;
        }
    }

}

// &lt;/editor-fold&gt;

// &lt;editor-fold defaultstate="collapsed" desc="Konstrukturen und Destruktoren"&gt;

myGUI::myGUI() {
    //Menu-Variablen

    unsigned int lowest = 1;
    unsigned int end = 4;
    int input = end;
    bool run = true;

    //Start
    cout &lt;&lt; "#### Kryptographie Sommersemester 2013 ####\n";
    cout &lt;&lt; "Nils Rogmann (725915) und Maximilian Krieg (725922)\n";

    // Begrüßung und Information
    cout &lt;&lt; "\nHerzlich willkommen.\n";
    cout &lt;&lt; "Das Programm wird nun mit Hilfe von Testvektoren geprueft.\n";

    // AES Check
    cout &lt;&lt; "\nAES:\t\t";
    if (checkAES()) {
        cout &lt;&lt; "OK";
    } else {
        cerr &lt;&lt; "Fehler";
    }

    // CBC Check
    cout &lt;&lt; "\nAES mit CBC:\t";
    if (checkCBC()) {
        cout &lt;&lt; "OK";
    } else {
        cerr &lt;&lt; "Fehler";
    }


    // ECB Check
    cout &lt;&lt; "\nAES mit ECB:\t";
    if (checkECB()) {
        cout &lt;&lt; "OK";
    } else {
        cerr &lt;&lt; "Fehler";
    }

    cout &lt;&lt; endl;

    //Menu Eingabe
    while (run) {
        cout &lt;&lt; "\nBitte waehlen sie aus:\n";
        cout &lt;&lt; "(1) AES\n";
        cout &lt;&lt; "(2) AES mit CBC\n";
        cout &lt;&lt; "(3) AES mit ECB\n";
        cout &lt;&lt; "(4) Programm beenden\n";
        cout &lt;&lt; "&gt; ";

        // Prüfe Eingabe auf Gültigkeit
        input = validatedInput(lowest, end);

        // Aufrufe
        if (input == 1) {
            cout &lt;&lt; "#### AES ####\n";
            menuAES();
            cout &lt;&lt; endl;
        }

        if (input == 2) {
            cout &lt;&lt; "#### AES mit CBC ####\n";
            menuCBC();
            cout &lt;&lt; endl;
        }


        if (input == 3) {
            cout &lt;&lt; "#### AES mit ECB ####\n";
            menuECB();
            cout &lt;&lt; endl;
        }

        // Fehler
        if (input == -1) {
            cerr &lt;&lt; "Ungueltige Eingabe getätigt.\nBitte nochmal eingeben.\n";
            cout &lt;&lt; endl;
        }

        // Beenden
        if (input == end) {

            cout &lt;&lt; "Programm wird beendet.\n";
            run = false;
            cout &lt;&lt; endl;
        }
    }
}//myGUI

myGUI::~myGUI() {
}//~myGUI

// &lt;/editor-fold&gt;
</code></pre>



<h3 class="wp-block-heading">support.h</h3>



<pre class="wp-block-code"><code>
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;vector&gt;
using namespace std;
typedef unsigned char uchar;

void printMatrix(vector&lt;uchar&gt; v, string name) {
    cout &lt;&lt; name &lt;&lt; ": \n";

    int add =0;
    for (int j = 0; j &lt; v.size()/16; j++) {
        for (int i = 0; i &lt; 4; i++) {
            cout &lt;&lt; hex &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; nouppercase &lt;&lt; (int) v&#91;i+add] &lt;&lt; " ";
            cout &lt;&lt; hex &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; nouppercase &lt;&lt; (int) v&#91;i + 4+add] &lt;&lt; " ";
            cout &lt;&lt; hex &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; nouppercase &lt;&lt; (int) v&#91;i + 8+add] &lt;&lt; " ";
            cout &lt;&lt; hex &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; nouppercase &lt;&lt; (int) v&#91;i + 12+add] &lt;&lt; " ";
            cout &lt;&lt; endl;
        }
        add=add+16;
        cout &lt;&lt; endl;
    }
    cout &lt;&lt; endl;
}

void printMatrix(uchar v&#91;16], string name) {
    cout &lt;&lt; name &lt;&lt; ": \n";
    for (int i = 0; i &lt; 4; i++) {
        cout &lt;&lt; hex &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; nouppercase &lt;&lt; (int) v&#91;i] &lt;&lt; " ";
        cout &lt;&lt; hex &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; nouppercase &lt;&lt; (int) v&#91;i + 4] &lt;&lt; " ";
        cout &lt;&lt; hex &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; nouppercase &lt;&lt; (int) v&#91;i + 8] &lt;&lt; " ";
        cout &lt;&lt; hex &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; nouppercase &lt;&lt; (int) v&#91;i + 12] &lt;&lt; " ";
        cout &lt;&lt; endl;
    }
    cout &lt;&lt; endl;

    /*
    for (int i=0;i&lt;16;i++)
        cout &lt;&lt; hex&lt;&lt;(int) v&#91;i];
     * */
}

int validatedInput(unsigned int lowest, unsigned int highest) {
    int tmp = 0;
    cin.clear();
    if (cin &gt;&gt; tmp) {//Eingabe ist in Ordnung
        cout &lt;&lt; endl;
        if (tmp &gt;= lowest &amp;&amp; tmp &lt;= highest) {//Eingabe liegt in den Parametern

            return tmp;
        }
    } else {
        // Falsche Inhalte verwerfen und Status zurücksetzen
        string trash = "";
        cin.clear();
        std::getline(std::cin, trash);
    }
    return -1;
}

// 16x16 Matrix ausgeben

void printImage(vector&lt;uchar&gt; myImg) {
    int add = 0;
    for (int j = 0; j &lt; 4; j++) {
        for (int i = 0; i &lt; 4; i++) {
            for (int k = 0; k &lt;= 60; k) {
                cout &lt;&lt; hex &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; nouppercase &lt;&lt; (int) myImg.at(i + k + add) &lt;&lt; " ";
                k = k + 4;
            }
            cout &lt;&lt; endl;
        }

        add = add + 64;
    }
    cout &lt;&lt; endl &lt;&lt; endl;
}

// 16x16 Matrix füllen

void fillImage(vector&lt;uchar&gt;&amp; v) {
    // Alles auf 0 setzen
    // Außer den Inneren bereich, diesen auf 1
    for (int y = 0; y &lt; 16; y++) {
        for (int x = 0; x &lt; 16; x++) {
            if (y == 5 || y == 6 || y == 9 || y == 10)
                v.push_back(0x1);
            else {
                v.push_back(0x0);
            }
        }
    }

    //Manuell Randpunkte des Kreises setzen
    v&#91;19] = 0x1;
    v&#91;22] = 0x1;
    v&#91;23] = 0x1;
    v&#91;26] = 0x1;
    v&#91;27] = 0x1;
    v&#91;30] = 0x1;
    v&#91;31] = 0x1;
    v&#91;34] = 0x1;
    v&#91;35] = 0x1;
    v&#91;38] = 0x1;
    v&#91;39] = 0x1;
    v&#91;42] = 0x1;
    v&#91;43] = 0x1;
    v&#91;47] = 0x1;
    v&#91;73] = 0x1;
    v&#91;74] = 0x1;
    v&#91;75] = 0x1;
    v&#91;76] = 0x1;
    v&#91;77] = 0x1;
    v&#91;78] = 0x1;
    v&#91;79] = 0x1;
    v&#91;112] = 0x1;
    v&#91;113] = 0x1;
    v&#91;114] = 0x1;
    v&#91;115] = 0x1;
    v&#91;117] = 0x1;
    v&#91;118] = 0x1;
    v&#91;119] = 0x1;
    v&#91;136] = 0x1;
    v&#91;137] = 0x1;
    v&#91;138] = 0x1;
    v&#91;140] = 0x1;
    v&#91;141] = 0x1;
    v&#91;142] = 0x1;
    v&#91;143] = 0x1;
    v&#91;176] = 0x1;
    v&#91;177] = 0x1;
    v&#91;178] = 0x1;
    v&#91;179] = 0x1;
    v&#91;180] = 0x1;
    v&#91;181] = 0x1;
    v&#91;182] = 0x1;
    v&#91;208] = 0x1;
    v&#91;212] = 0x1;
    v&#91;213] = 0x1;
    v&#91;216] = 0x1;
    v&#91;217] = 0x1;
    v&#91;220] = 0x1;
    v&#91;221] = 0x1;
    v&#91;224] = 0x1;
    v&#91;225] = 0x1;
    v&#91;228] = 0x1;
    v&#91;229] = 0x1;
    v&#91;232] = 0x1;
    v&#91;233] = 0x1;
    v&#91;236] = 0x1;
}

// Gleichheitsprüfung

template&lt;class T&gt;
bool areEqual(T arr1, T arr2) {
    bool tmp = false;
    for (int i = 0; i &lt; 16; i++) {
        if (arr1&#91;i] == arr2&#91;i]) {
            tmp = true;
        } else {
            cout &lt;&lt; hex &lt;&lt; arr1&#91;i] &lt;&lt; "!=" &lt;&lt; arr2&#91;i] &lt;&lt; endl;
            tmp = false;
            break;
        }
    }
    return tmp;
}</code></pre>



<p class="wp-block-paragraph"></p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/05/kryptologie-praktikum-4/">Kryptologie (Praktikum 4)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://maximiliankrieg.de/2013/05/kryptologie-praktikum-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kryptologie (Vorlesung 8)</title>
		<link>https://maximiliankrieg.de/2013/05/kryptologie-vorlesung-8/</link>
					<comments>https://maximiliankrieg.de/2013/05/kryptologie-vorlesung-8/#respond</comments>
		
		<dc:creator><![CDATA[Maximilian]]></dc:creator>
		<pubDate>Tue, 28 May 2013 18:16:00 +0000</pubDate>
				<category><![CDATA[Kryptologie]]></category>
		<guid isPermaLink="false">https://maximiliankrieg.de/?p=2730</guid>

					<description><![CDATA[<p>Skript-Anfang Skript &#8211; Seite 29 Skript-Ende Skript &#8211; Seite 32 Praktikum Evaluation Datenauthentisierung Message Authentication Code (MAC) Erste Idee zur Umsetzung Erklärung Authentisierung Prüfung Dieses&#8230;</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/05/kryptologie-vorlesung-8/">Kryptologie (Vorlesung 8)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Skript-Anfang</th><td>Skript &#8211; Seite 29</td></tr><tr><th>Skript-Ende</th><td>Skript &#8211; Seite 32</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">Praktikum</h3>



<ul class="wp-block-list">
<li>Das was abgegeben wurde ist in Ordnung</li>



<li>Wenn etwas nicht stimmt, meldet er sich von selbst</li>
</ul>



<h3 class="wp-block-heading">Evaluation</h3>



<ul class="wp-block-list">
<li>Wurde durchgeführt</li>
</ul>



<h3 class="wp-block-heading">Datenauthentisierung</h3>



<ul class="wp-block-list">
<li>Garantiert, dass Daten nicht verändert wurden</li>



<li><strong>Dazu:</strong>
<ul class="wp-block-list">
<li>Beweisender (B) ist der Sender / Erzeuger von Daten</li>



<li>B berechnet mittels eines kryptographischen Schlüssels eine Prüfsumme über die zu authentifizierenden Daten</li>



<li>Prüfer (P) überprüft die Prüfsumme mittels eines kryptographischen Schlüssels</li>
</ul>
</li>



<li><strong>Wir unterscheiden:</strong>
<ol class="wp-block-list">
<li>Symmetrische Verfahren (Schlüssel zur Berechnung = Schlüssel zur Prüfung)</li>



<li>Asymmetrische Verfahren (Schlüssel zur Berechnung ≠ Schlüssel zur Prüfung)</li>
</ol>
</li>
</ul>



<h3 class="wp-block-heading">Message Authentication Code (MAC)</h3>



<ul class="wp-block-list">
<li><strong>Siehe auch: </strong><a href="http://de.wikipedia.org/wiki/Message_Authentication_Code">http://de.wikipedia.org/wiki/Message_Authentication_Code</a></li>



<li>Symmetrisches Verfahren</li>



<li>Basieren häufig auf Blockchiffren oder Hash-Funktionen</li>



<li>B und P müssen vorab einen symmetrischen Schlüssel ausgetauscht haben</li>
</ul>



<h4 class="wp-block-heading">Erste Idee zur Umsetzung</h4>



<ul class="wp-block-list">
<li>Basierend auf einer Hash-Funktion M:{0,1}<sup>*</sup> → {0,1}<sup>n</sup></li>



<li>B und P vereinbaren Schlüssel k ∈ {0,1}<sup>128</sup></li>
</ul>



<h4 class="wp-block-heading">Erklärung</h4>



<ul class="wp-block-list">
<li>Hashfunktion nach Merkle-Damgard</li>



<li>|| bedeutet &#8222;direkt hintereinander&#8220;</li>



<li>H(k||m) = Funktion zur Berechnung der Prüfsumme</li>



<li>k= Schlüssel</li>



<li>m = Nachricht</li>



<li>c = Prüfummse</li>
</ul>



<h4 class="wp-block-heading">Authentisierung</h4>



<ul class="wp-block-list">
<li><strong>B authentisiert m ∈ {0,1}<sup>*</sup></strong>
<ol class="wp-block-list">
<li>Berechne c = M(k||m)</li>



<li>Sende m und c an P</li>
</ol>
</li>
</ul>



<h4 class="wp-block-heading">Prüfung</h4>



<ul class="wp-block-list">
<li><strong>P prüft Authentizität von m</strong>
<ol class="wp-block-list">
<li>Berechne c&#8216; = M(k||m)</li>



<li>Prüft ob c=c&#8216; gilt</li>
</ol>
</li>
</ul>



<h4 class="wp-block-heading">Dieses Verfahren ist unsicher</h4>



<ul class="wp-block-list">
<li>Angreifer kann weitere Blöcke an m hängen, Hashwert weiter rechnen und so eine gültige Prüfsumme berechnen</li>



<li>Schützt also nur den Anfang einer Nachricht, aber nicht das Ende
<ul class="wp-block-list">
<li>→ <em>&#8222;Wir greifen morgen um 10 Uhr an&#8220;</em></li>



<li>→ <em>&#8222;Wir greifen morgen um 10 Uhr an, wenn es nicht regnet&#8220;</em></li>
</ul>
</li>



<li>Auch H(m||k) keine gute Idee, denn das schützt auch nur das Ende der Nachricht und nicht den Anfang</li>
</ul>



<h4 class="wp-block-heading">Beispiel für eine Length Extension Attack</h4>



<ul class="wp-block-list">
<li>Normalerweise braucht ein Angreifer den Schlüssel um eine neue Prüfsumme zu erzeugen</li>



<li>Mit einer Length Extension Attack wird die Prüfsumme wieder in die Hashfunktion eingegeben und man setzt am Ende wieder an</li>



<li>Die Länge der ursprünglichen Nachricht muss dafür bekannt sein</li>



<li>Neue Prüfsumme und Daten werden übermittelt</li>
</ul>



<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>&#8211;</th><th>Original</th><th>Modifiziert</th></tr><tr><td>Data</td><td>count=10&amp;lat=37.351&amp;user_id=1&amp;long=-119.827&amp;waffle=eggo</td><td>count=10&amp;lat=37.351&amp;user_id=1&amp;long=-119.827&amp;waffle=eggo<ins>&amp;waffle=liege</ins></td></tr><tr><td>Signature</td><td>6d5f807e23db210bc254a28be2d6759a0f5f5d99</td><td>0e41270260895979317fff3898ab85668953aaa2</td></tr></tbody></table></figure>



<h4 class="wp-block-heading">Sichere MAC-Verfahren</h4>



<ol class="wp-block-list">
<li>CMAC basiert auf Blockchiffren (C=Chiffre)</li>



<li>HMAC basiert auf Hash-Funktionen (Hash)
<ul class="wp-block-list">
<li>HMAC(k,m) = H((ko+opad)||H((ko+ipad)||m))</li>



<li>opad = 0x5C &#8230; 5C (Schlüssellänge)</li>



<li>ipad = 0x36 &#8230; 36 (Schlüssellänge)</li>



<li>H((ko+ipad)||m) → Sichert den Anfang der Nachricht ab</li>



<li>H((ko+opad)||H((ko+ipad)||m)) → Sichert das Ende der Nachricht ab</li>
</ul>
</li>
</ol>



<figure data-wp-context="{&quot;imageId&quot;:&quot;6a241258b4bf8&quot;}" data-wp-interactive="core/image" data-wp-key="6a241258b4bf8" class="wp-block-image size-full wp-lightbox-container"><img loading="lazy" decoding="async" width="500" height="401" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on--pointerdown="actions.preloadImage" data-wp-on--pointerenter="actions.preloadImageWithDelay" data-wp-on--pointerleave="actions.cancelPreload" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130528_2.png" alt="" class="wp-image-2731" srcset="https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130528_2.png 500w, https://maximiliankrieg.de/wp-content/uploads/2026/06/kyl_20130528_2-300x241.png 300w" sizes="auto, (max-width: 500px) 100vw, 500px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			data-wp-bind--aria-label="state.thisImage.triggerButtonAriaLabel"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.thisImage.buttonRight"
			data-wp-style--top="state.thisImage.buttonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h3 class="wp-block-heading">Verschlüsselungsverfahren und MAC-Verfahren</h3>



<ul class="wp-block-list">
<li>Werden häufig zusammen geschaltet</li>



<li>Secure Messaging</li>



<li>Vertraulicher und authentischer Tunnel / Kanal</li>



<li>MAC-Verfahren müssen <strong>nicht die Vertraulichkeit</strong>garantieren</li>



<li>MAC-Verfahren erfüllen <strong>nicht das Schutzziel Nichtabstreitbarkeit</strong>
<ul class="wp-block-list">
<li>Prüfer und und Beweisender verwenden den gleichen Schlüssel</li>



<li>Auch P könnte die Daten authentisiert haben</li>



<li>Gegenüber Dritten ist nicht nachweisbar, ob B oder P die Daten authentisiert hat</li>
</ul>
</li>



<li><strong>Zwei Nebenbedingungen:</strong>
<ol class="wp-block-list">
<li>Setze für Verschlüsselung und Datenauthentifizierung verschiedener Schlüssel ein (<em>&#8222;Trenne wo du trennen kannst&#8220;</em>)</li>



<li>Erst Verschlüsseln → dann verschlüsselte Daten Authentisieren (Vertraulichkeit ist ein anderes Schutzziel als Authentizität)</li>
</ol>
</li>
</ul>



<h3 class="wp-block-heading">Signaturverfahren</h3>



<ul class="wp-block-list">
<li>Sind asymmetrische Authentifizierungsverfahren</li>



<li>B nutzt geheimen Schlüssel zur Berechnung der Prüfsumme</li>



<li>P prüft mittels öffentlichem Schlüssel</li>



<li>Erfüllt auch das Schutzziel <strong>Nichtabstreitbarkeit</strong> → Prüfsumme nur vom Inhaber des geheimen Schlüssels berechnet werden</li>



<li>Zum Beispiel RSA oder Digital Signature Algorithm (DSA)</li>
</ul>



<h3 class="wp-block-heading">RSA</h3>



<ul class="wp-block-list">
<li>B nutzt geheimen Schlüssel d um Prüfsumme S = m<sup>d</sup> mod n zu berechnen</li>



<li>P nutzt öffentlichen Schlüssel e um m&#8216; = s<sup>e</sup> mod n zu berechnen</li>



<li>Wegen (m<sup>d</sup>)<sup>e</sup> = mod n = m akzeptiert P, wenn m&#8216; = m</li>



<li><strong>Besteht aus:</strong>
<ol class="wp-block-list">
<li>Hashfunktion H:{0,1}<sup>*</sup> → {0,1}<sup>n</sup> ( Um Sicherheitsniveau 100 Bit zu erreichen muss n >= 200 sein)</li>



<li>Einem Signaturalgorithmus</li>
</ol>
</li>
</ul>



<h4 class="wp-block-heading">Problem</h4>



<ul class="wp-block-list">
<li>Es können nur Nachrichten der Länge m ≤ n signiert werden</li>



<li>Für n ≈2<sup>2000</sup> als Bitlänge ≤ 2000</li>
</ul>



<h4 class="wp-block-heading">Lösung</h4>



<ul class="wp-block-list">
<li>Nachricht m wird zunächst gehasht</li>



<li>Signiert und geprüft wird dann H(m)</li>



<li>Dazu wichtig: Hashfunktion muss <strong>kollisionsresistent</strong> sein</li>



<li>Gilt für zwei Nachrichten m und m&#8216; → H(m) = H(m&#8216;) → dann ist eine gültige Signatur für m auch eine für m&#8216;</li>
</ul>



<h3 class="wp-block-heading">DSA</h3>



<ul class="wp-block-list">
<li>Sicherheit beruhrt auf der vermuteten Schwere des Diskreten Logarithmusproblems in bestimmten endlichen Gruppen</li>



<li>Diskretes Logarithmusprublem in Z<sup>*</sup><sub>p</sub> = {1, &#8230; , p-1}</li>



<li>Gegegeben: Zwei Elemente g,h ∈ Z<sup>*</sup><sub>p</sub></li>



<li>Lösung: log<sub>g</sub>h (d.h. x mit g<sup>x</sup> = h)</li>
</ul>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/05/kryptologie-vorlesung-8/">Kryptologie (Vorlesung 8)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://maximiliankrieg.de/2013/05/kryptologie-vorlesung-8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Kryptologie (Praktikum 3)</title>
		<link>https://maximiliankrieg.de/2013/05/kryptologie-praktikum-3/</link>
					<comments>https://maximiliankrieg.de/2013/05/kryptologie-praktikum-3/#respond</comments>
		
		<dc:creator><![CDATA[Maximilian]]></dc:creator>
		<pubDate>Wed, 15 May 2013 18:28:00 +0000</pubDate>
				<category><![CDATA[Kryptologie]]></category>
		<guid isPermaLink="false">https://maximiliankrieg.de/?p=2754</guid>

					<description><![CDATA[<p>Skript-Anfang Kryptouebung2 &#8211; Seite 1 Skript-Ende Kryptouebung2 &#8211; Seite 1 main.cpp myGUI.h myGUI.cpp myAES.h myAES.cpp myCBC.h myCBC.cpp myECB.h myECB.cpp</p>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/05/kryptologie-praktikum-3/">Kryptologie (Praktikum 3)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><th>Skript-Anfang</th><td>Kryptouebung2 &#8211; Seite 1</td></tr><tr><th>Skript-Ende</th><td>Kryptouebung2 &#8211; Seite 1</td></tr></tbody></table></figure>



<h3 class="wp-block-heading">main.cpp</h3>



<pre class="wp-block-code"><code>
// Präprozessor-Direktiven
#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include "myGUI.h"

// Using-Deklarationen
using namespace std;

int main(int argc, char** argv) {
    myGUI gui;
}// main
</code></pre>



<h3 class="wp-block-heading">myGUI.h</h3>



<pre class="wp-block-code"><code>
#ifndef MYGUI_H
#define	MYGUI_H

#include &lt;iostream&gt;
#include "myCBC.h"
#include "myECB.h"

class myGUI {
public:
    myGUI();
    void callAES();
    void callCBC();
    void callECB();
    bool checkAES();
    bool checkCBC();
    bool checkECB();
    int validatedInput(unsigned int, unsigned int);
    virtual ~myGUI();
private:
};

#endif	/* MYGUI_H */
</code></pre>



<h3 class="wp-block-heading">myGUI.cpp</h3>



<pre class="wp-block-code"><code>
#include "myGUI.h"
#include &lt;vector&gt;

using namespace std;

bool areEqual(vector&lt;uchar&gt; v1, vector&lt;uchar&gt; v2) {
    bool tmp = false;
    if (v1.size() == v2.size()) {
        for (int i = 0; i &lt; v1.size(); i++) {
            if (v1&#91;i] == v2&#91;i]) {
                tmp = true;
            } else {
                cout &lt;&lt; hex &lt;&lt; v1&#91;i] &lt;&lt; "!=" &lt;&lt; v2&#91;i] &lt;&lt; endl;
                tmp = false;
                break;
            }
        }
    }
    return tmp;
}

bool areEqual(uchar* arr1, uchar* arr2) {
    bool tmp = false;
    for (int i = 0; i &lt; 16; i++) {
        if (arr1&#91;i] == arr2&#91;i]) {
            tmp = true;
        } else {
            cout &lt;&lt; hex &lt;&lt; arr1&#91;i] &lt;&lt; "!=" &lt;&lt; arr2&#91;i] &lt;&lt; endl;
            tmp = false;
            break;
        }
    }
    return tmp;
}

bool myGUI::checkCBC() {
    bool returnValue = false;

    //16 Byte Testvektoren
    uchar keyB&#91;16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
    uchar ivB&#91;16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
    uchar klartextB1&#91;16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
    uchar ciphertextB1&#91;16] = {0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46, 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d};
    vector&lt;uchar&gt; cipherB1;
    vector&lt;uchar&gt; ktB;

    for (int i = 0; i &lt; 16; i++) {
        ktB.push_back(klartextB1&#91;i]);
        cipherB1.push_back(ciphertextB1&#91;i]);
    }

    myCBC cbcB;
    cbcB.setKey(keyB);
    cbcB.setIV(ivB);
    cbcB.setKlartext(ktB);
    cbcB.crypt(false);

    // 32 Byte Testvektoren

    uchar klartextA1&#91;16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
    uchar klartextA2&#91;16] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f};
    uchar ivA&#91;16] = {0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28, 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58};
    uchar keyA&#91;16] = {0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0, 0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a};
    uchar ciphertextA1&#91;16] = {0xd2, 0x96, 0xcd, 0x94, 0xc2, 0xcc, 0xcf, 0x8a, 0x3a, 0x86, 0x30, 0x28, 0xb5, 0xe1, 0xdc, 0x0a};
    uchar ciphertextA2&#91;16] = {0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9, 0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1};
    vector&lt;uchar&gt; cipherA1;

    vector&lt;uchar&gt; test;

    for (int i = 0; i &lt; 16; i++) {
        test.push_back(klartextA1&#91;i]);
        cipherA1.push_back(ciphertextA1&#91;i]);
    }

    for (int i = 0; i &lt; 16; i++) {
        test.push_back(klartextA2&#91;i]);
        cipherA1.push_back(ciphertextA2&#91;i]);
    }

    myCBC cbcA;
    cbcA.setKey(keyA);
    cbcA.setIV(ivA);
    cbcA.setKlartext(test);
    cbcA.crypt(false);

    //Prüfung
    bool isWorking = areEqual(cbcA.getCiphertext(), cipherA1) &amp;&amp; areEqual(cbcB.getCiphertext(), cipherB1);

    if (isWorking) {
        returnValue = true;
    } else {
        returnValue = false;
    }
    return returnValue;
}

bool myGUI::checkECB() {
    bool returnValue = false;

    //16 Byte Testvektoren
    uchar schluessel&#91;16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};

    uchar klartext_1&#91;16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
    uchar klartext_2&#91;16] = {0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51};
    uchar klartext_3&#91;16] = {0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef};

    uchar cipher_1&#91;16] = {0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60, 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97};
    uchar cipher_2&#91;16] = {0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d, 0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf};
    uchar cipher_3&#91;16] = {0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23, 0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88};
    vector&lt;uchar&gt; cipherB1;
    vector&lt;uchar&gt; ktB;

    for (int i = 0; i &lt; 16; i++) {
        ktB.push_back(klartext_1&#91;i]);
        cipherB1.push_back(cipher_1&#91;i]);
    }

    for (int i = 0; i &lt; 16; i++) {
        ktB.push_back(klartext_2&#91;i]);
        cipherB1.push_back(cipher_2&#91;i]);
    }

    for (int i = 0; i &lt; 16; i++) {
        ktB.push_back(klartext_3&#91;i]);
        cipherB1.push_back(cipher_3&#91;i]);
    }

    myECB ecb;
    ecb.setKey(schluessel);
    ecb.setKlartext(ktB);
    ecb.crypt(false);

    //Prüfung
    bool isWorking = areEqual(ecb.getCiphertext(), cipherB1);

    if (isWorking) {
        returnValue = true;
    } else {
        returnValue = false;
    }
    return returnValue;
}

bool myGUI::checkAES() {

    bool returnValue = false;
    uchar schluessel&#91;16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};

    uchar klartext_1&#91;16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};
    uchar klartext_2&#91;16] = {0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51};
    uchar klartext_3&#91;16] = {0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef};

    uchar cipher_1&#91;16] = {0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60, 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97};
    uchar cipher_2&#91;16] = {0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d, 0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf};
    uchar cipher_3&#91;16] = {0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23, 0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88};

    myAES aes1;
    aes1.setKlartext(klartext_1);
    aes1.setSchluessel(schluessel);
    aes1.crypt(false);

    myAES aes2;
    aes2.setKlartext(klartext_2);
    aes2.setSchluessel(schluessel);
    aes2.crypt(false);

    myAES aes3;
    aes3.setKlartext(klartext_3);
    aes3.setSchluessel(schluessel);
    aes3.crypt(false);

    bool isWorking = areEqual(aes3.getCiphertext(), cipher_3) &amp;&amp; areEqual(aes2.getCiphertext(), cipher_2) &amp;&amp; areEqual(aes1.getCiphertext(), cipher_1);
    if (isWorking) {
        returnValue = true;
    } else {

        returnValue = false;
    }
    return returnValue;
}

void myGUI::callAES() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    myAES aes;
    aes.crypt(false);
    //myAES aesDecrypt;
    bool run = true;
    unsigned int lowest = 1;
    unsigned int end = 5;
    int input = end;

    //Menu Eingabe
    while (run) {
        cout &lt;&lt; "\nBitte waehlen sie aus:\n";
        cout &lt;&lt; "(1) Text verschluesseln \n";
        cout &lt;&lt; "(2) Text und Schluessel eingeben \n";
        cout &lt;&lt; "(3) Text und Schluessel aus Datei laden\n";
        cout &lt;&lt; "(4) Entschluesseln \n";
        cout &lt;&lt; "(5) Zurueck\n";
        cout &lt;&lt; "&gt; ";
        input = validatedInput(lowest, end);
        if (input == 1) {
            aes.crypt(true);
        }
        if (input == 2) {
            aes.enterKlartext();
            aes.enterSchluessel();
            aes.crypt(true);
        }
        if (input == 3) {
            cerr &lt;&lt; RED_start &lt;&lt; "Noch nicht implementiert\n" &lt;&lt; RED_end;
        }
        if (input == 4) {
            aes.decrypt(true);
        }
        if (input == 5) {
            run = false;
        }
        if (input == -1) {

            cerr &lt;&lt; RED_start &lt;&lt; "Ungueltige Eingabe getätigt.\nBitte nochmal eingeben.\n" &lt;&lt; RED_end;
            cout &lt;&lt; endl;
        }
    }
}

void myGUI::callCBC() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    myCBC cbc;
    cbc.crypt(true);
    bool run = true;
    unsigned int lowest = 1;
    unsigned int end = 5;
    int input = end;

    //Menu Eingabe
    while (run) {

        cout &lt;&lt; "\nBitte waehlen sie aus:\n";
        cout &lt;&lt; "(1) Text verschluesseln \n";
        cout &lt;&lt; "(2) Text und Schluessel eingeben \n";
        cout &lt;&lt; "(3) Text und Schluessel aus Datei laden\n";
        cout &lt;&lt; "(4) Text entschluesseln\n";
        cout &lt;&lt; "(5) Zurueck\n";
        cout &lt;&lt; "&gt; ";
        input = validatedInput(lowest, end);
        if (input == 1) {
            cbc.crypt(true);
        }
        if (input == 2) {
            cbc.enterIV();
            cbc.enterKey();
            cbc.enterKlartext();
            cbc.crypt(true);
        }
        if (input == 3) {
            cerr &lt;&lt; RED_start &lt;&lt; "Noch nicht implementiert\n" &lt;&lt; RED_end;
        }
        if (input == 4) {
            cbc.decrypt(true);
        }
        if (input == 5) {
            run = false;
        }
        if (input == -1) {
            cerr &lt;&lt; RED_start &lt;&lt; "Ungueltige Eingabe getätigt.\nBitte nochmal eingeben.\n" &lt;&lt; RED_end;
            cout &lt;&lt; endl;
        }
    }

}

void myGUI::callECB() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    myECB ecb;
    ecb.crypt(false);
    bool run = true;
    unsigned int lowest = 1;
    unsigned int end = 5;
    int input = end;

    //Menu Eingabe
    while (run) {

        cout &lt;&lt; "\nBitte waehlen sie aus:\n";
        cout &lt;&lt; "(1) Text verschluesseln \n";
        cout &lt;&lt; "(2) Text und Schluessel eingeben \n";
        cout &lt;&lt; "(3) Text und Schluessel aus Datei laden\n";
        cout &lt;&lt; "(4) Text entschluesseln\n";
        cout &lt;&lt; "(5) Zurueck\n";
        cout &lt;&lt; "&gt; ";
        input = validatedInput(lowest, end);
        if (input == 1) {
            ecb.crypt(true);
        }
        if (input == 2) {
            ecb.enterKey();
            ecb.enterKlartext();
            ecb.crypt(true);
        }
        if (input == 3) {
            cerr &lt;&lt; RED_start &lt;&lt; "Noch nicht implementiert\n" &lt;&lt; RED_end;
        }
        if (input == 4) {
                ecb.decrypt(true);
        }
        if (input == 5) {
            run = false;
        }
        if (input == -1) {
            cerr &lt;&lt; RED_start &lt;&lt; "Ungueltige Eingabe getätigt.\nBitte nochmal eingeben.\n" &lt;&lt; RED_end;
            cout &lt;&lt; endl;
        }
    }

}

int myGUI::validatedInput(unsigned int lowest, unsigned int highest) {
    int tmp = 0;
    cin.clear();
    if (cin &gt;&gt; tmp) {//Eingabe ist in Ordnung
        cout &lt;&lt; endl;
        if (tmp &gt;= lowest &amp;&amp; tmp &lt;= highest) {//Eingabe liegt in den Parametern

            return tmp;
        }
    } else {
        string trash = "";
        cin.clear();
        std::getline(std::cin, trash);
    }
    return -1;
}

myGUI::myGUI() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    string GREEN_start = "\033&#91;22;32m";
    string GREEN_end = "\033&#91;0m";
    //Menu-Variablen

    unsigned int lowest = 1;
    unsigned int end = 4;
    int input = end;
    bool run = true;

    //Start
    cout &lt;&lt; "#### Kryptographie Sommersemester 2013 ####\n";
    cout &lt;&lt; "Nils Rogmann (725915) und Maximilian Krieg (725922)\n";

    // Begrüßung und Information
    cout &lt;&lt; "\nHerzlich willkommen.\n";
    cout &lt;&lt; "Das Programm wird nun mit Hilfe von Testvektoren geprüft.\n";

    // AES Check
    cout &lt;&lt; "\nAES:\t\t";
    if (checkAES()) {
        cout &lt;&lt; GREEN_start &lt;&lt; "OK" &lt;&lt; GREEN_end;
    } else {
        cerr &lt;&lt; RED_start &lt;&lt; "Fehler" &lt;&lt; RED_end;
    }

    // CBC Check
    cout &lt;&lt; "\nAES mit CBC:\t";
    if (checkCBC()) {
        cout &lt;&lt; GREEN_start &lt;&lt; "OK" &lt;&lt; GREEN_end;
    } else {
        cerr &lt;&lt; RED_start &lt;&lt; "Fehler" &lt;&lt; RED_end;
    }


    // ECB Check
    cout &lt;&lt; "\nAES mit ECB:\t";
    if (checkECB()) 
    {
        cout &lt;&lt; GREEN_start &lt;&lt; "OK" &lt;&lt; GREEN_end;
    }
    else
    {
        cerr &lt;&lt; RED_start &lt;&lt; "Fehler" &lt;&lt; RED_end;
    }
    cout &lt;&lt; endl;

    //Menu Eingabe
    while (run) {
        cout &lt;&lt; "\nBitte waehlen sie aus:\n";
        cout &lt;&lt; "(1) AES\n";
        cout &lt;&lt; "(2) AES mit CBC\n";
        cout &lt;&lt; "(3) AES mit ECB\n";
        cout &lt;&lt; "(4) Programm beenden\n";
        cout &lt;&lt; "&gt; ";

        input = validatedInput(lowest, end);

        // Aufrufe
        if (input == 1) {
            cout &lt;&lt; GREEN_start &lt;&lt; "#### AES ####\n" &lt;&lt; GREEN_end;
            callAES();
            cout &lt;&lt; endl;
        }

        if (input == 2) {
            cout &lt;&lt; GREEN_start &lt;&lt; "#### AES mit CBC ####\n" &lt;&lt; GREEN_end;
            callCBC();
            cout &lt;&lt; endl;
        }


        if (input == 3) {
            cout &lt;&lt; GREEN_start &lt;&lt; "#### AES mit ECB ####\n" &lt;&lt; GREEN_end;
            callECB();
            cout &lt;&lt; endl;
        }

        // Fehler
        if (input == -1) {
            cerr &lt;&lt; RED_start &lt;&lt; "Ungueltige Eingabe getätigt.\nBitte nochmal eingeben.\n" &lt;&lt; RED_end;
            cout &lt;&lt; endl;
        }

        // Beenden
        if (input == end) {

            cout &lt;&lt; "Programm wird beendet.\n";
            run = false;
            cout &lt;&lt; endl;
        }
    }
}

myGUI::~myGUI() {
}
</code></pre>



<h3 class="wp-block-heading">myAES.h</h3>



<pre class="wp-block-code"><code>
#ifndef MYAES_H
#define	MYAES_H

#include &lt;iostream&gt;

using namespace std;
// Typedefs
typedef unsigned char uchar;

class myAES {
public:
    // Konstruktoren/Destruktoren
    myAES();
    virtual ~myAES();

    // Manuelle Eingabe
    void enterKlartext();
    void enterSchluessel();

    // Set/Get-Methoden
    void setKlartext(uchar&#91;16]);
    void setSchluessel(uchar&#91;16]);
    void setCiphertext(uchar&#91;16]);
    uchar* getKlartext();
    uchar* getSchluessel();
    uchar* getCiphertext();

    // AES-Methoden
    void crypt(bool);
    void mixcolumns();
    void shiftrows();
    void schluesselexpansion(uchar&#91;]&#91;44], int, int, int);
    void rotword(uchar&#91;], int);
    uchar mix(uchar, unsigned int);
    void subbytes(uchar &#91;], uchar &#91;], int);

    // Print-Methoden
    void printSchluessel();
    void printCiphertext();
    void printKlartext();
    
   void decrypt(bool) ;
   uchar gmul(uchar, uchar);
   void invert_mixcolumns();
   void invert_shiftrows();

private:
    uchar klartext&#91;16];
    uchar schluessel&#91;16];
    uchar ciphertext&#91;16];
};



#endif	/* MYAES_H */
</code></pre>



<h3 class="wp-block-heading">myAES.cpp</h3>



<pre class="wp-block-code"><code>
#include "myAES.h"

using namespace std;

unsigned char Sbox&#91;256] = {//  s-box
    0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
    0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
    0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
    0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
    0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
    0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
    0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
    0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
    0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
    0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
    0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
    0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
    0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
    0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
    0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
    0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
};

unsigned char sbox_inverse&#91;256] = {
    0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
    0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
    0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
    0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
    0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
    0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
    0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
    0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
    0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
    0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
    0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
    0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
    0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
    0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
    0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
    0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
};

unsigned char Rcon&#91;256] = {
    0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a,
    0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39,
    0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
    0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8,
    0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef,
    0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
    0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b,
    0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3,
    0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
    0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
    0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35,
    0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
    0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04,
    0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63,
    0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
    0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d
};

void myAES::subbytes(uchar sbox&#91;], uchar tmp&#91;], int arrSize) {
    for (int i = 0; i &lt; arrSize; i++) {
        tmp&#91;i] = sbox&#91;tmp&#91;i]];
    }
}// subbytes

uchar myAES::mix(uchar byte, unsigned int mixvalue) {
    unsigned char retValue;
    switch (mixvalue) {
        case 1:
            retValue = byte;
            break;
        case 2:
            retValue = byte &lt;&lt; 1;
            if (byte &amp; 0x80) {
                retValue = retValue ^ 0x1b;
            }
            break;
        case 3:
            retValue = byte &lt;&lt; 1;
            if (byte &amp; 0x80) {
                retValue = retValue ^ 0x1b;
            }
            retValue = retValue^byte;
            break;
    }
    return retValue;
}

void addRoundKey(uchar klartext&#91;], int iLaenge, uchar matrix&#91;]&#91;44], int iReihe, int iSpalte, int iRunde) {
    int pos = 0;
    for (int i = iRunde * 4; i &lt; ((iRunde * 4) + 4) &amp;&amp; i &lt; iSpalte; i++) {
        for (int k = 0; k &lt; iReihe; k++) {
            klartext&#91;pos] = klartext&#91;pos] ^ matrix&#91;k]&#91;i];
            pos++;
        }
    }
}// addroundkey

void myAES::rotword(uchar column&#91;], int iReihe) {
    uchar tmp = column&#91;0];
    for (int i = 1; i &lt; iReihe; i++) {
        column&#91;i - 1] = column&#91;i];
    }
    column&#91;iReihe - 1] = tmp;
} // rotword

void myAES::schluesselexpansion(uchar matrix&#91;]&#91;44], int iReihe, int iSpalte, int iLaenge) {
    // Alle Spalten durchlaufen
    int pos = 0;

    for (int i = 0; i &lt; iSpalte; i++) {
        if (i &lt; 4) { // Schluessel in erste vier Spalten kopieren
            for (int k = 0; k &lt; iReihe &amp;&amp; pos &lt; iLaenge; k++) {
                matrix&#91;k]&#91;i] = schluessel&#91;pos];
                pos++;
                //cout &lt;&lt; hex &lt;&lt; "matrix&#91;" &lt;&lt; k &lt;&lt; "]&#91;" &lt;&lt; i &lt;&lt; "] = " &lt;&lt; (int) matrix&#91;k]&#91;i] &lt;&lt; endl;
            }
        } else { // i &gt; 4
            if (i % 4 == 0) {// erste Spalte eines Schluessels
                // Spalte in Hilfsarray kopieren
                uchar tmp&#91;iReihe]; // i-1
                uchar tmp2&#91;iReihe]; // i-4
                for (int k = 0; k &lt; iReihe; k++) {
                    tmp&#91;k] = matrix&#91;k]&#91;i - 1];
                    tmp2&#91;k] = matrix&#91;k]&#91;i - 4];
                }

                rotword(tmp, iReihe);

                subbytes(Sbox, tmp, iReihe);

                // Spalte&#91;i-4] XOR subbytes&#91;rotword&#91;i-i]
                for (int k = 0; k &lt; iReihe; k++) {
                    tmp&#91;k] = tmp&#91;k] ^ tmp2&#91;k];
                }

                // tmp&#91;0] XOR (i/4)
                tmp&#91;0] = tmp&#91;0] ^ Rcon&#91;i / iReihe];

                // tmp&#91;k] an Spalte&#91;k]&#91;i] kopieren
                for (int k = 0; k &lt; iReihe; k++) {
                    matrix&#91;k]&#91;i] = tmp&#91;k];
                }

            } else {
                //cout &lt;&lt; "i " &lt;&lt; i &lt;&lt; endl;
                for (int k = 0; k &lt; iReihe; k++) {
                    matrix&#91;k]&#91;i] = matrix&#91;k]&#91;i - 4] ^ matrix&#91;k]&#91;i - 1];
                }
            }
        }
    }
}// schluesselexpansion

void myAES::shiftrows() {
    uchar copys&#91;16] = {};

    //reihe 1   
    copys&#91;0] = ciphertext&#91;0];
    copys&#91;4] = ciphertext&#91;4];
    copys&#91;8] = ciphertext&#91;8];
    copys&#91;12] = ciphertext&#91;12];

    //reihe 2
    copys&#91;1] = ciphertext&#91;5];
    copys&#91;5] = ciphertext&#91;9];
    copys&#91;9] = ciphertext&#91;13];
    copys&#91;13] = ciphertext&#91;1];

    // reihe 3
    copys&#91;2] = ciphertext&#91;10];
    copys&#91;6] = ciphertext&#91;14];
    copys&#91;10] = ciphertext&#91;2];
    copys&#91;14] = ciphertext&#91;6];

    //reihe 4
    copys&#91;3] = ciphertext&#91;15];
    copys&#91;7] = ciphertext&#91;3];
    copys&#91;11] = ciphertext&#91;7];
    copys&#91;15] = ciphertext&#91;11];

    //umschreiben   
    for (int i = 0; i &lt; 16; i++) {
        ciphertext&#91;i] = copys&#91;i];
    }
}// shiftrows

void myAES::mixcolumns() {
    for (int i = 0; i &lt; 4; i++) {
        uchar sj0 = mix(ciphertext&#91;i * 4], 2)^mix(ciphertext&#91;i * 4 + 1], 3)^mix(ciphertext&#91;i * 4 + 2], 1)^mix(ciphertext&#91;i * 4 + 3], 1);
        uchar sj1 = mix(ciphertext&#91;i * 4], 1)^mix(ciphertext&#91;i * 4 + 1], 2)^mix(ciphertext&#91;i * 4 + 2], 3)^mix(ciphertext&#91;i * 4 + 3], 1);
        uchar sj2 = mix(ciphertext&#91;i * 4], 1)^mix(ciphertext&#91;i * 4 + 1], 1)^mix(ciphertext&#91;i * 4 + 2], 2)^mix(ciphertext&#91;i * 4 + 3], 3);
        uchar sj3 = mix(ciphertext&#91;i * 4], 3)^mix(ciphertext&#91;i * 4 + 1], 1)^mix(ciphertext&#91;i * 4 + 2], 1)^mix(ciphertext&#91;i * 4 + 3], 2);
        ciphertext&#91;i * 4] = sj0;
        ciphertext&#91;i * 4 + 1] = sj1;
        ciphertext&#91;i * 4 + 2] = sj2;
        ciphertext&#91;i * 4 + 3] = sj3;
    }
}// mixcolumns

void myAES::crypt(bool output) {

    // Parameter
    int iRunde = 10;
    int iLaenge = 16;

    // Überschreibe ciphertext um diesen fortan zu verwenden
    for (int i = 0; i &lt; 16; i++) {
        ciphertext&#91;i] = klartext&#91;i];
    }

    // Arraygroesse dynamisch bestimmen
    int arrSize = sizeof (ciphertext) / sizeof (ciphertext&#91;0]);

    // Zwischenspeicherung der Rundenschluessel
    int iReihe = 4;
    int iSpalte = 4 * (iRunde + 1);
    uchar carrRundenschluessel&#91;4]&#91;44];

    // Schluessel expandieren
    schluesselexpansion(carrRundenschluessel, iReihe, iSpalte, iLaenge);

    // Vorrunde
    for (int k = 0; k &lt; iLaenge; k++) {
        ciphertext&#91;k] = ciphertext&#91;k] ^ schluessel&#91;k];
    }

    // Durchlaufen der Runden
    for (int i = 1; i &lt; iRunde + 1; i++) {

        // S-Box
        subbytes(Sbox, ciphertext, arrSize);

        // Shift Rows
        shiftrows();

        // Mix Columns
        if (i != (iRunde)) { // kein MixColumns in der letzten Runde
            mixcolumns();
        }

        // Rundenschlüssel addieren
        addRoundKey(ciphertext, arrSize, carrRundenschluessel, iReihe, iSpalte, i);

    }

    // Ausgabe des Ciphertexts
    if (output) {
        printSchluessel();
        printKlartext();
        printCiphertext();
    }
}

void myAES::invert_shiftrows() {
    uchar copys&#91;16] = {};

    //reihe 1   
    copys&#91;0] = klartext&#91;0];
    copys&#91;4] = klartext&#91;4];
    copys&#91;8] = klartext&#91;8];
    copys&#91;12] = klartext&#91;12];

    //reihe 2
    copys&#91;1] = klartext&#91;13];
    copys&#91;13] = klartext&#91;9];
    copys&#91;9] = klartext&#91;5];
    copys&#91;5] = klartext&#91;1];

    // reihe 3   
    copys&#91;6] = klartext&#91;14];
    copys&#91;2] = klartext&#91;10];
    copys&#91;14] = klartext&#91;6];
    copys&#91;10] = klartext&#91;2];

    //reihe 4
    copys&#91;11] = klartext&#91;15];
    copys&#91;7] = klartext&#91;11];
    copys&#91;3] = klartext&#91;7];
    copys&#91;15] = klartext&#91;3];

    //umschreiben   
    for (int i = 0; i &lt; 16; i++) {
        klartext&#91;i] = copys&#91;i];
    }
}// invert_shiftrows

void myAES::invert_mixcolumns() {
    for (int i = 0; i &lt; 4; i++) {
        uchar sj0 = gmul(klartext&#91;i * 4], 14)^gmul(klartext&#91;i * 4 + 1], 11)^gmul(klartext&#91;i * 4 + 2], 13)^gmul(klartext&#91;i * 4 + 3], 9);
        uchar sj1 = gmul(klartext&#91;i * 4], 9)^gmul(klartext&#91;i * 4 + 1], 14)^gmul(klartext&#91;i * 4 + 2], 11)^gmul(klartext&#91;i * 4 + 3], 13);
        uchar sj2 = gmul(klartext&#91;i * 4], 13)^gmul(klartext&#91;i * 4 + 1], 9)^gmul(klartext&#91;i * 4 + 2], 14)^gmul(klartext&#91;i * 4 + 3], 11);
        uchar sj3 = gmul(klartext&#91;i * 4], 11)^gmul(klartext&#91;i * 4 + 1], 13)^gmul(klartext&#91;i * 4 + 2], 9)^gmul(klartext&#91;i * 4 + 3], 14);
        klartext&#91;i * 4] = sj0;
        klartext&#91;i * 4 + 1] = sj1;
        klartext&#91;i * 4 + 2] = sj2;
        klartext&#91;i * 4 + 3] = sj3;
    }
}

uchar myAES::gmul(uchar a, uchar b) {
    unsigned char p = 0;
    unsigned char hi;

    for (int i = 0; i &lt; 8; ++i) {
        if ((b &amp; 1) == 1)
            p ^= a;
        hi = (a &amp; 0x80);
        a &lt;&lt;= 1;
        if (hi == 0x80)
            a ^= 0x1b;
        b &gt;&gt;= 1;
    }
    return p;
}

void myAES::decrypt(bool output) {

    // Parameter
    int iRunde = 10;
    int iLaenge = 16;


    // Überschreibe klartext um diesen fortan zu verwenden
    for (int i = 0; i &lt; 16; i++) {
        klartext&#91;i] = ciphertext&#91;i];
    }


    // Arraygroesse dynamisch bestimmen
    int arrSize = sizeof (klartext) / sizeof (klartext&#91;0]);

    // Zwischenspeicherung der Rundenschluessel
    int iReihe = 4;
    int iSpalte = 4 * (iRunde + 1);
    uchar carrRundenschluessel&#91;4]&#91;44];

    // Schluessel expandieren
    schluesselexpansion(carrRundenschluessel, iReihe, iSpalte, iLaenge);

    //printRundenSchluessel(carrRundenschluessel, iReihe, iSpalte);

    // "neue" Vorrunde
    addRoundKey(klartext, arrSize, carrRundenschluessel, iReihe, iSpalte, 10);

    // Durchlaufen der Runden
    for (int i = 9; i &gt; 0; i--) {

        // Shift Rows
        invert_shiftrows();

        // S-Box
        subbytes(sbox_inverse, klartext, arrSize);

        // Rundenschlüssel addieren
        addRoundKey(klartext, arrSize, carrRundenschluessel, iReihe, iSpalte, i);

        // Mix Columns
        if (i != 10) { // kein MixColumns in der letzten Runde
            invert_mixcolumns();
        }
    }


    // Letzte Runde
    invert_shiftrows();
    subbytes(sbox_inverse, klartext, arrSize);

    for (int k = 0; k &lt; iLaenge; k++) {
        klartext&#91;k] = klartext&#91;k] ^ schluessel&#91;k];
    }

    // Ausgabe des Ciphertexts
    if (output) {
        printSchluessel();
        printCiphertext();
        printKlartext();
    }
}// decrypt

void myAES::printSchluessel() {
    cout &lt;&lt; endl &lt;&lt; "Schluessel:\n";
    for (int i = 0; i &lt; 4; i++)
        cout &lt;&lt; hex &lt;&lt; "\t0x" &lt;&lt; (int) schluessel&#91;0 + i] &lt;&lt; "\t0x" &lt;&lt; (int) schluessel &#91;4 + i] &lt;&lt; "\t0x" &lt;&lt; (int) schluessel &#91;8 + i] &lt;&lt; "\t0x" &lt;&lt; (int) schluessel&#91;12 + i] &lt;&lt; endl;
    cout &lt;&lt; endl;
}

void myAES::printCiphertext() {
    cout &lt;&lt; endl &lt;&lt; "Ciphertext:\n";
    for (int i = 0; i &lt; 4; i++)
        cout &lt;&lt; hex &lt;&lt; "\t0x" &lt;&lt; (int) ciphertext&#91;0 + i] &lt;&lt; "\t0x" &lt;&lt; (int) ciphertext &#91;4 + i] &lt;&lt; "\t0x" &lt;&lt; (int) ciphertext &#91;8 + i] &lt;&lt; "\t0x" &lt;&lt; (int) ciphertext&#91;12 + i] &lt;&lt; endl;
    cout &lt;&lt; endl;
}

void myAES::printKlartext() {
    cout &lt;&lt; endl &lt;&lt; "Klartext:\n";
    for (int i = 0; i &lt; 4; i++)
        cout &lt;&lt; hex &lt;&lt; "\t0x" &lt;&lt; (int) klartext&#91;0 + i] &lt;&lt; "\t0x" &lt;&lt; (int) klartext &#91;4 + i] &lt;&lt; "\t0x" &lt;&lt; (int) klartext &#91;8 + i] &lt;&lt; "\t0x" &lt;&lt; (int) klartext&#91;12 + i] &lt;&lt; endl;
    cout &lt;&lt; endl;
}

myAES::myAES() {
    uchar kt&#91;16] = {0x61, 0x62, 0x62, 0x69, 0x6c, 0x64, 0x75, 0x6e, 0x67, 0x73, 0x6d, 0x61, 0x74, 0x72, 0x69, 0x78};
    uchar s&#91;16] = {0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31};
    //uchar c&#91;16] = {0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31};
    for (int i = 0; i &lt; 16; i++) {
        schluessel&#91;i] = s&#91;i];
        klartext&#91;i] = kt&#91;i];
    }
}

myAES::~myAES() {
}

void myAES::enterKlartext() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    string GREEN_start = "\033&#91;22;32m";
    string GREEN_end = "\033&#91;0m";
    string tmp = "";
    int diff = 0;
    cout &lt;&lt; "Klartext (16 Zeichen):";
    if (cin &gt;&gt; tmp) {

        if (tmp.length() &gt; 16) {
            cerr &lt;&lt; RED_start &lt;&lt; "\nWerte fuer den Klartext zu groß. Trenne nach 16 Zeichen ab.\n(" &lt;&lt; GREEN_start;
            for (int i = 0; i &lt; tmp.length(); i++) {
                if (i == 16) {
                    cerr &lt;&lt; RED_start &lt;&lt; " | ";
                }
                cerr &lt;&lt; tmp.at(i);
            }
            cout &lt;&lt; ")" &lt;&lt; RED_end &lt;&lt; endl;
        }

        if (tmp.length() &lt; 16) {
            cerr &lt;&lt; RED_start &lt;&lt; "\nWert fuer den Klartext zu klein. Fuelle mit Nullen auf.\n";
            diff = 16 - tmp.length();
            for (int i = 0; i &lt; diff; i++) {
                tmp.push_back('\0');
            }
            cout &lt;&lt; RED_end &lt;&lt; endl;
        }

        for (int i = 0; i &lt; 16; i++) {
            klartext&#91;i] = tmp&#91;i];
        }
        cout &lt;&lt; endl;

    }
}

void myAES::enterSchluessel() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    string GREEN_start = "\033&#91;22;32m";
    string GREEN_end = "\033&#91;0m";
    string tmp = "";
    int diff = 0;
    cout &lt;&lt; "Schluessel (16 Zeichen):";
    if (cin &gt;&gt; tmp) {

        if (tmp.length() &gt; 16) {
            cerr &lt;&lt; RED_start &lt;&lt; "\nWerte fuer den Schluessel zu groß. Trenne nach 16 Zeichen ab.\n(" &lt;&lt; GREEN_start;
            for (int i = 0; i &lt; tmp.length(); i++) {
                if (i == 16) {
                    cerr &lt;&lt; RED_start &lt;&lt; " | ";
                }
                cerr &lt;&lt; tmp.at(i);
            }
            cout &lt;&lt; ")" &lt;&lt; RED_end &lt;&lt; endl;
        }

        if (tmp.length() &lt; 16) {
            cerr &lt;&lt; RED_start &lt;&lt; "\nWert fuer den Schluessel zu klein. Fuelle mit Nullen auf.\n";
            diff = 16 - tmp.length();
            for (int i = 0; i &lt; diff; i++) {
                tmp.push_back('\0');
            }
            cout &lt;&lt; RED_end &lt;&lt; endl;
        }

        for (int i = 0; i &lt; 16; i++) {
            schluessel&#91;i] = tmp&#91;i];
            //cout &lt;&lt; hex &lt;&lt; tmp&#91;i];
        }
        cout &lt;&lt; endl;

    }
}

void myAES::setCiphertext(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        ciphertext&#91;i] = tmp&#91;i];
    }

}

void myAES::setKlartext(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        klartext&#91;i] = tmp&#91;i];
    }
}

void myAES::setSchluessel(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        schluessel&#91;i] = tmp&#91;i];

    }
}

uchar* myAES::getSchluessel() {
    return schluessel;
}

uchar* myAES::getCiphertext() {
    return ciphertext;
}

uchar* myAES::getKlartext() {
    return klartext;
}
</code></pre>



<h3 class="wp-block-heading">myCBC.h</h3>



<pre class="wp-block-code"><code>
#ifndef MYCBC_H
#define	MYCBC_H
#include "myAES.h"
#include &lt;vector&gt;
class myCBC {
public:
    // Konstruktoren / Destruktoren
    myCBC();
    virtual ~myCBC();
    
    //CBC
    void crypt(bool);
    void decrypt(bool);
    
    // Set/Get-Methoden
    void setKey(uchar&#91;16]);
    void setIV(uchar&#91;16]);
    void setKlartext(vector&lt;uchar&gt;);
    void setCiphertext(vector&lt;uchar&gt;);

    vector&lt;uchar&gt; getKlartext();
    vector&lt;uchar&gt; getCiphertext();
    uchar* getSchluessel();
    uchar* getIV();
    
    // Manuelle Eingabe
    void enterKey();
    void enterIV();
    void enterKlartext();
    
    // Print-Methoden
    void printSchluessel();
    void printCiphertext();
    void printKlartext();
    
private:
    //unsigned int stellen;
    uchar iv&#91;16];
    uchar key&#91;16];
    vector&lt;uchar&gt; klartext;
    vector&lt;uchar&gt; ciphertext;

};

#endif	/* MYCBC_H */
</code></pre>



<h3 class="wp-block-heading">myCBC.cpp</h3>



<pre class="wp-block-code"><code>
#include "myCBC.h"

void myCBC::enterKey() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    string GREEN_start = "\033&#91;22;32m";
    string GREEN_end = "\033&#91;0m";
    string tmp = "";
    int diff = 0;
    cout &lt;&lt; "Schluessel (16 Zeichen):";
    if (cin &gt;&gt; tmp) {

        if (tmp.length() &gt; 16) {
            cerr &lt;&lt; RED_start &lt;&lt; "\nWerte fuer den Schluessel zu groß. Trenne nach 16 Zeichen ab.\n(" &lt;&lt; GREEN_start;
            for (int i = 0; i &lt; tmp.length(); i++) {
                if (i == 16) {
                    cerr &lt;&lt; RED_start &lt;&lt; " | ";
                }
                cerr &lt;&lt; tmp.at(i);
            }
            cout &lt;&lt; ")" &lt;&lt; RED_end &lt;&lt; endl;
        }

        if (tmp.length() &lt; 16) {
            cerr &lt;&lt; RED_start &lt;&lt; "\nWert fuer den Schluessel zu klein. Fuelle mit Nullen auf.\n";
            diff = 16 - tmp.length();
            for (int i = 0; i &lt; diff; i++) {
                tmp.push_back('\0');
            }
            cout &lt;&lt; RED_end &lt;&lt; endl;
        }

        for (int i = 0; i &lt; 16; i++) {
            key&#91;i] = tmp&#91;i];
        }
        cout &lt;&lt; endl;

    }
}

void myCBC::enterIV() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    string GREEN_start = "\033&#91;22;32m";
    string GREEN_end = "\033&#91;0m";
    string tmp = "";
    int diff = 0;
    cout &lt;&lt; "IV (16 Zeichen):";
    if (cin &gt;&gt; tmp) {

        if (tmp.length() &gt; 16) {
            cerr &lt;&lt; RED_start &lt;&lt; "\nWerte fuer den IV zu groß. Trenne nach 16 Zeichen ab.\n(" &lt;&lt; GREEN_start;
            for (int i = 0; i &lt; tmp.length(); i++) {
                if (i == 16) {
                    cerr &lt;&lt; RED_start &lt;&lt; " | ";
                }
                cerr &lt;&lt; tmp.at(i);
            }
            cout &lt;&lt; ")" &lt;&lt; RED_end &lt;&lt; endl;
        }

        if (tmp.length() &lt; 16) {
            cerr &lt;&lt; RED_start &lt;&lt; "\nWert fuer den IV zu klein. Fuelle mit Nullen auf.\n";
            diff = 16 - tmp.length();
            for (int i = 0; i &lt; diff; i++) {
                tmp.push_back('\0');
            }
            cout &lt;&lt; RED_end &lt;&lt; endl;
        }

        for (int i = 0; i &lt; 16; i++) {
            iv&#91;i] = tmp&#91;i];
        }
        cout &lt;&lt; endl;

    }
}

void myCBC::enterKlartext() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    klartext.clear();
    string tmp = "";
    cout &lt;&lt; "Klartext (Beliebig viele Zeichen):";
    if (cin &gt;&gt; tmp) {
        for (int i = 0; i &lt; tmp.size(); i++) {
            klartext.push_back(tmp&#91;i]);
        }
        cout &lt;&lt; endl;
    }

    if (tmp.size() % 16 != 0) {
        cerr &lt;&lt; RED_start &lt;&lt; "\nLetzter Klartext-Block nicht vollstaendig. Fuelle mit Nullen auf.\n";
        for (int i = 0; i &lt; 16 - tmp.size() % 16; i++) {
            klartext.push_back('\0');
        }
        cout &lt;&lt; RED_end &lt;&lt; endl;
    }
}

myCBC::myCBC() {

    // Default Parameter
    uchar newKey&#91;16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
    uchar newIV&#91;16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
    uchar newKlartext&#91;16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};

    // Schluessel setzen
    for (int i = 0; i &lt; 16; i++) {
        key&#91;i] = newKey&#91;i];
    }

    //IV setzen
    for (int i = 0; i &lt; 16; i++) {
        iv&#91;i] = newIV&#91;i];
    }

    // Klartext setzen
    for (int i = 0; i &lt; 16; i++) {
        klartext.push_back(newKlartext&#91;i]);
    }
}

void myCBC::printSchluessel() {
    cout &lt;&lt; endl &lt;&lt; "Schluessel:\n";
    for (int i = 0; i &lt; 4; i++)
        cout &lt;&lt; hex &lt;&lt; "\t0x" &lt;&lt; (int) key&#91;0 + i] &lt;&lt; "\t0x" &lt;&lt; (int) key &#91;4 + i] &lt;&lt; "\t0x" &lt;&lt; (int) key &#91;8 + i] &lt;&lt; "\t0x" &lt;&lt; (int) key&#91;12 + i] &lt;&lt; endl;
    cout &lt;&lt; endl;
}

void myCBC::printCiphertext() {
    cout &lt;&lt; endl &lt;&lt; "Ciphertext:\n";
    for (int i = 0; i &lt; ciphertext.size(); i++) {
        cout &lt;&lt; std::hex &lt;&lt; " 0x" &lt;&lt; (int) ciphertext&#91;i];
    }
}

void myCBC::printKlartext() {
    cout &lt;&lt; endl &lt;&lt; "Klartext:\n";
    for (int i = 0; i &lt; klartext.size(); i++) {
        cout &lt;&lt; std::hex &lt;&lt; " 0x" &lt;&lt; (int) klartext&#91;i];
    }
}

vector&lt;uchar&gt; myCBC::getCiphertext() {
    return ciphertext;
}

void myCBC::decrypt(bool print) {
    klartext.clear();
    uchar tmp_iv&#91;16];
    for (int j = 0; j &lt; 16; j++) {
        tmp_iv&#91;j] = iv&#91;j];
    }
    //printSchluessel();
    //printKlartext();
    //printCiphertext();
    for (int i = 0; i &lt; ciphertext.size() / 16; i++) {

        myAES a1;

        //Übergabe - Array
        uchar tmp&#91;16];
        for (int j = 0; j &lt; 16; j++) {
            tmp&#91;j] = ciphertext&#91;j + 16 * i];
        }

        // Ciphertext
        a1.setCiphertext(tmp);

        // Schluessel
        a1.setSchluessel(key);

        // crypt
        a1.decrypt(false);

        // Resultat mit IV addieren
        for (int j = 0; j &lt; 16; j++) {

            a1.getKlartext()&#91;j] = a1.getKlartext()&#91;j]^tmp_iv&#91;j];
        }

        for (int j = 0; j &lt; 16; j++) {
            tmp_iv&#91;j] = a1.getCiphertext()&#91;j + 16 * i];
            klartext.push_back(a1.getKlartext()&#91;j]);
        }
    }

    if (print) {
        printSchluessel();
        printCiphertext();
        printKlartext();
    }

}

void myCBC::crypt(bool print) {
    ciphertext.clear();
    uchar tmp_iv&#91;16];
    for (int i = 0; i &lt; 16; i++) {
        tmp_iv&#91;i] = iv&#91;i];
    }

    for (int i = 0; i &lt; klartext.size() / 16; i++) {

        myAES a1;
        a1.setSchluessel(key);

        //XOR in Übergabe - Array
        uchar tmp&#91;16];
        for (int j = 0; j &lt; 16; j++) {
            tmp&#91;j] = klartext&#91;j + 16 * i]^tmp_iv&#91;j];
        }

        // Klartext
        a1.setKlartext(tmp);

        // crypt
        a1.crypt(false);


        for (int j = 0; j &lt; 16; j++) {
            tmp_iv&#91;j] = a1.getCiphertext()&#91;j];
            ciphertext.push_back(a1.getCiphertext()&#91;j]);
        }
    }

    if (print) {
        printSchluessel();
        printKlartext();
        printCiphertext();
    }
}

void myCBC::setKlartext(vector&lt;uchar&gt; kt) {
    if (kt.size() &gt; klartext.size()) {
        int diff = kt.size() - klartext.size();
        for (int i = 0; i &lt; diff; i++) {
            klartext.push_back(0x00);
        }
    }
    for (int i = 0; i &lt; kt.size(); i++) {
        klartext.at(i) = kt.at(i);
    }
}

void myCBC::setIV(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        iv&#91;i] = tmp&#91;i];
    }
}

void myCBC::setKey(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        key&#91;i] = tmp&#91;i];
    }
}

myCBC::~myCBC() {
}
</code></pre>



<h3 class="wp-block-heading">myECB.h</h3>



<pre class="wp-block-code"><code>

#ifndef MYECB_H
#define	MYECB_H

#include "myAES.h"
#include &lt;vector&gt;
class myECB {
public:
    // Konstruktoren / Destruktoren
    myECB();
    virtual ~myECB();
    
    //CBC
    void crypt(bool);
    void decrypt(bool);
    
    // Set/Get-Methoden
    void setKey(uchar&#91;16]);
    
    void setKlartext(vector&lt;uchar&gt;);
    void setCiphertext(vector&lt;uchar&gt;);

    vector&lt;uchar&gt; getKlartext();
    vector&lt;uchar&gt; getCiphertext();
    uchar* getSchluessel();
    
    
    // Manuelle Eingabe
    void enterKey();
    
    void enterKlartext();
    
    // Print-Methoden
    void printSchluessel();
    void printCiphertext();
    void printKlartext();
    
private:
    //unsigned int stellen;
    
    uchar key&#91;16];
    vector&lt;uchar&gt; klartext;
    vector&lt;uchar&gt; ciphertext;

};

#endif	/* MYECB_H */
</code></pre>



<h3 class="wp-block-heading">myECB.cpp</h3>



<pre class="wp-block-code"><code>

#include "myECB.h"

void myECB::enterKey() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    string GREEN_start = "\033&#91;22;32m";
    string GREEN_end = "\033&#91;0m";
    string tmp = "";
    int diff = 0;
    cout &lt;&lt; "Schluessel (16 Zeichen):";
    if (cin &gt;&gt; tmp) {

        if (tmp.length() &gt; 16) {
            cerr &lt;&lt; RED_start &lt;&lt; "\nWerte fuer den Schluessel zu groß. Trenne nach 16 Zeichen ab.\n(" &lt;&lt; GREEN_start;
            for (int i = 0; i &lt; tmp.length(); i++) {
                if (i == 16) {
                    cerr &lt;&lt; RED_start &lt;&lt; " | ";
                }
                cerr &lt;&lt; tmp.at(i);
            }
            cout &lt;&lt; ")" &lt;&lt; RED_end &lt;&lt; endl;
        }

        if (tmp.length() &lt; 16) {
            cerr &lt;&lt; RED_start &lt;&lt; "\nWert fuer den Schluessel zu klein. Fuelle mit Nullen auf.\n";
            diff = 16 - tmp.length();
            for (int i = 0; i &lt; diff; i++) {
                tmp.push_back('\0');
            }
            cout &lt;&lt; RED_end &lt;&lt; endl;
        }

        for (int i = 0; i &lt; 16; i++) {
            key&#91;i] = tmp&#91;i];
        }
        cout &lt;&lt; endl;

    }
}

void myECB::enterKlartext() {
    string RED_start = "\033&#91;22;31m";
    string RED_end = "\033&#91;0m";
    klartext.clear();
    string tmp = "";
    cout &lt;&lt; "Klartext (Beliebig viele Zeichen):";
    if (cin &gt;&gt; tmp) {
        for (int i = 0; i &lt; tmp.size(); i++) {
            klartext.push_back(tmp&#91;i]);
        }
        cout &lt;&lt; endl;
    }

    if (tmp.size() % 16 != 0) {
        cerr &lt;&lt; RED_start &lt;&lt; "\nLetzter Klartext-Block nicht vollstaendig. Fuelle mit Nullen auf.\n";
        for (int i = 0; i &lt; 16 - tmp.size() % 16; i++) {
            klartext.push_back('\0');
        }
        cout &lt;&lt; RED_end &lt;&lt; endl;
    }
}

myECB::myECB() {

    // Default Parameter
    uchar newKey&#91;16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
    uchar newIV&#91;16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
    uchar newKlartext&#91;16] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a};

    // Schluessel setzen
    for (int i = 0; i &lt; 16; i++) {
        key&#91;i] = newKey&#91;i];
    }

    // Klartext setzen
    for (int i = 0; i &lt; 16; i++) {
        klartext.push_back(newKlartext&#91;i]);
    }
}

void myECB::printSchluessel() {
    cout &lt;&lt; endl &lt;&lt; "Schluessel:\n";
    for (int i = 0; i &lt; 4; i++)
        cout &lt;&lt; hex &lt;&lt; "\t0x" &lt;&lt; (int) key&#91;0 + i] &lt;&lt; "\t0x" &lt;&lt; (int) key &#91;4 + i] &lt;&lt; "\t0x" &lt;&lt; (int) key &#91;8 + i] &lt;&lt; "\t0x" &lt;&lt; (int) key&#91;12 + i] &lt;&lt; endl;
    cout &lt;&lt; endl;
}

void myECB::printCiphertext() {
    cout &lt;&lt; endl &lt;&lt; "Ciphertext:\n";
    for (int i = 0; i &lt; ciphertext.size(); i++) {
        cout &lt;&lt; std::hex &lt;&lt; " 0x" &lt;&lt; (int) ciphertext&#91;i];
    }
}

void myECB::printKlartext() {
    cout &lt;&lt; endl &lt;&lt; "Klartext:\n";
    for (int i = 0; i &lt; klartext.size(); i++) {
        cout &lt;&lt; std::hex &lt;&lt; " 0x" &lt;&lt; (int) klartext&#91;i];
    }
}

vector&lt;uchar&gt; myECB::getCiphertext() {
    return ciphertext;
}

void myECB::decrypt(bool print) {
    klartext.clear();

    for (int i = 0; i &lt; ciphertext.size() / 16; i++) {

        myAES a1;

        //Übergabe - Array
        uchar tmp&#91;16];
        for (int j = 0; j &lt; 16; j++) {
            tmp&#91;j] = ciphertext&#91;j + 16 * i];
        }

        // Ciphertext
        a1.setCiphertext(tmp);

        // Schluessel
        a1.setSchluessel(key);

        // crypt
        a1.decrypt(false);

        // Resultat mit IV addieren
        for (int j = 0; j &lt; 16; j++) {
            klartext.push_back(a1.getKlartext()&#91;j]);
        }
    }

    if (print) {
        printSchluessel();
        printCiphertext();
        printKlartext();
    }

}

void myECB::crypt(bool print) {
    ciphertext.clear();
    /* uchar tmp_iv&#91;16];
     for (int i = 0; i &lt; 16; i++) {
         tmp_iv&#91;i] = iv&#91;i];
     }*/

    for (int i = 0; i &lt; klartext.size() / 16; i++) {

        myAES a1;
        a1.setSchluessel(key);

        //XOR in Übergabe - Array
        uchar tmp&#91;16];
        for (int j = 0; j &lt; 16; j++) {
            tmp&#91;j] = klartext&#91;j + 16 * i]; //^tmp_iv&#91;j];
        }

        // Klartext
        a1.setKlartext(tmp);

        // crypt
        a1.crypt(false);


        for (int j = 0; j &lt; 16; j++) {
            //tmp_iv&#91;j] = a1.getCiphertext()&#91;j];
            ciphertext.push_back(a1.getCiphertext()&#91;j]);
        }
    }

    if (print) {
        printSchluessel();
        printKlartext();
        printCiphertext();
    }
}

void myECB::setKlartext(vector&lt;uchar&gt; kt) {
    if (kt.size() &gt; klartext.size()) {
        int diff = kt.size() - klartext.size();
        for (int i = 0; i &lt; diff; i++) {
            klartext.push_back(0x00);
        }
    }
    for (int i = 0; i &lt; kt.size(); i++) {
        klartext.at(i) = kt.at(i);
    }
}

void myECB::setKey(uchar tmp&#91;16]) {
    for (int i = 0; i &lt; 16; i++) {
        key&#91;i] = tmp&#91;i];
    }
}

myECB::~myECB() {
}</code></pre>
<p>Der Beitrag <a href="https://maximiliankrieg.de/2013/05/kryptologie-praktikum-3/">Kryptologie (Praktikum 3)</a> erschien zuerst auf <a href="https://maximiliankrieg.de">Maximilian Krieg</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://maximiliankrieg.de/2013/05/kryptologie-praktikum-3/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
