import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import java.io.ByteArrayOutputStream;
import java.security.*;
import java.util.Base64;

public class ExerciseMain {

    protected static String toHexString(byte[] data, int offset) {
        //sorgt dafür das Offset immer gültig ist. Wenn Offset negativ ist
        if (offset <0) {
            //wird Offset auf 0 gesetzt
            offset=0;
        }

        //erzeugt StringBuilder-Objekt, um Hexadezimal-String schrittweise aufzubauen
        //effizienter als Verkettung von Strings mit Plus-Operator
        StringBuilder sb = new StringBuilder();

        //geht durch jedes Byte im Byte-Array
        for (int i=0; i<data.length; i++) {
            //jedes Byte wird in zweistelligen Hexadezimalwert umgewandelt
            sb.append(String.format("%02X", data[i]));
            //wenn Offset größer 0 ist und aktuelle Position (i+1) kleiner als die Länge von data und Offset an aktueller Position (i+1) teilbar ist
            if ((offset >0) && (i+1<data.length) && ((i+1) % offset == 0)) {
                //fügt Leerzeichen hinzu
                sb.append(" ");
            }
        }
        //gibt Hexadezimal-String zurück
        return sb.toString();
    }

    // Print a nice headline/separator.
    protected static void printHeadline(String headline, String symbol) {
        int width=130;
        String s = symbol;

        if (s.length() != 1) {
            s = " ";
        }
        System.out.println();
        System.out.println(s.repeat(width));
        System.out.println(s + " " + headline);
        System.out.println(s.repeat(width));
        System.out.println();
    }

    protected static void printHeadline(String headline) {
        printHeadline(headline, "=");
    }

    protected static void aufgabe1() {
        printHeadline("Aufgabe 1: Kryptografische Hash-Funktionen.");

        try {
            /*******************************************************************
             * Teilaufgabe a
             *******************************************************************/

            /*******************************************************************
             * Teilaufgabe b
             *******************************************************************/

        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected static void aufgabe2() {
        printHeadline("Aufgabe 2: Symmetrische Verschlüsselung.");

        try {
            /*******************************************************************
             * Teilaufgabe a
             *******************************************************************/

            /*******************************************************************
             * Teilaufgabe b
             *******************************************************************/


        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    protected static void aufgabe3() {
        printHeadline("Aufgabe 3: Asymmetrische Verschlüsselung.");

        try {
            /*******************************************************************
             * Teilaufgabe a
             *******************************************************************/


            /*******************************************************************
             * Teilaufgabe b
             *******************************************************************/

        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected static void aufgabe4() {
        printHeadline("Aufgabe 4: Digitale Signaturen.");

        try {
            /*******************************************************************
             * Teilaufgabe a
             *******************************************************************/

            /*******************************************************************
             * Teilaufgabe b
             *******************************************************************/

        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) throws Exception {

        aufgabe1();
        aufgabe2();
        aufgabe3();
        aufgabe4();

    }
}
