public void receiveFirst() {
    System.out.println("-- Bob --");
    if (MitM) {
      System.out.println("ACHTUNG: MitM aktiv!!!");
    }

    // fingerprint werte aus datei auslesen
    fingerprint = new Fingerprint(new File("HashParameter"));

    // bob bekommt p und g von alice
    p = new BigInteger(Com.receive(), 16); // R1
    g = new BigInteger(Com.receive(), 16); // R2
    System.out.println("p: " + p);
    System.out.println("g: " + g);

    // bob bekommt öffentlichen rsa schlüssel von alice
    BigInteger e_A = new BigInteger(Com.receive(), 16); // R3
    BigInteger n_A = new BigInteger(Com.receive(), 16); // R4
    System.out.println("Alice e: " + e_A);
    System.out.println("Alice n: " + n_A);

    // bob sendet seinen öffentlichen schlüssel
    RSA rsa_B = new RSA();
    System.out.println("RSA Bob e: " + rsa_B.e);
    System.out.println("RSA Bob n: " + rsa_B.n);
    System.out.println("RSA Bob d: " + rsa_B.d);
    Com.sendTo(0, rsa_B.e.toString(16)); // S5
    Com.sendTo(0, rsa_B.n.toString(16)); // S6

    // bob empfängt y_A
    BigInteger y_A = new BigInteger(Com.receive(), 16); // R7
    System.out.println("y_A: " + y_A);

    // zufällige zahl x_B in {1,...,p-2} -> randomBetween 1 <= x_B < p-1
    BigInteger x_B = BigIntegerUtil.randomBetween(ONE, p.subtract(ONE));
    // bob wählt x_B = g^(x_B) mod p
    BigInteger y_B = g.modPow(x_B, p);

    // bob bestimmt schlüssel
    BigInteger k = y_A.modPow(x_B, p);
    System.out.println("k: " + k.toString());

    // signatur
    BigInteger hash = hash(y_B, y_A);
    BigInteger S_B = rsa_B.getSignatur(hash); // S_B = hash^d_B mod n_B
    System.out.println("Signatur S_B: " + S_B);

    // zertifikat generieren
    Certificate Z_B = generateCertificate(rsa_B.e, rsa_B.n);
    System.out.println("Z_B");
    printCertificate(Z_B);

    // encrypted S_B with idea
    BigInteger key = getIDEAKeyBasedOnK(k);
    BigInteger iv = new BigInteger(IV, 16);
    idea = new IDEA(key, iv);
    BigInteger S_B_encrypted = idea.encipher(S_B);

    // bob sendet certificate in einzelteilen
    Com.sendTo(0, Z_B.getID()); // send ID // S8
    // String data_send = new String(Z_B.getData());
    String data_send = serialize(Z_B.getData());
    System.out.println("data send: " + data_send);
    Com.sendTo(0, data_send); // send data (pub key) // S9
    Com.sendTo(0, Z_B.getSignature().toString(16)); // send signature //S10

    // bob sendet y_B
    Com.sendTo(0, y_B.toString(16)); // S11

    // bob sendet S_B_encrypted
    Com.sendTo(0, S_B_encrypted.toString(16)); // S12

    System.out.println("Bob: Receive cert");

    // bob empfängt certificate in einzelteilen
    Certificate Z_A = buildCertificateBasedOnStrings(Com.receive(), Com.receive(), Com.receive()); // R13,14,15

    // check certificate
    if (checkCertificate(Z_A) == true) {
      System.out.println("Zertifikat Check: Zertifikat von Alice ist korrekt!");
    } else {
      System.out.println("Zertifikat Check: Zertifikat von Alice ist NICHT korrekt! ABBRUCH!");
      System.exit(0);
    }

    // bob empfängt S_A_encrypted
    BigInteger S_A_encrypted = new BigInteger(Com.receive(), 16); // R16

    // decrypt S_A_encrypted with idea
    BigInteger S_A = idea.decipher(S_A_encrypted);

    // bob überprüft die gültigkeit von S_B
    BigInteger hash2 = hash(y_A, y_B);
    if (checkSignature(hash2, S_A, e_A, n_A) == true) {
      System.out.println("Signature Check: hashs h(y_A, y_B) sind gleich! Bob akzeptiert k!");
    } else {
      System.out.println("Signature Check: Hashs nicht gleich! ABBRUCH!");
      System.exit(0);
    }

    // Chat Start
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    String input = "";
    while (true) {

      String receive = Com.receive();
      BigInteger receiveInteger = new BigInteger(receive, 16);
      BigInteger receiveInteger_decrypted = idea.decipher(receiveInteger);

      System.out.println("Message from Alice: " + new String(receiveInteger_decrypted.toByteArray()));

      System.out.print("Enter your message (Enter q for quit): ");
      System.out.flush(); // empties buffer, before you input text
      try {
        input = stdin.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }

      System.out.println("Your message: " + input);

      if (input.equalsIgnoreCase("q")) {
        System.exit(0);
      }

      BigInteger inputInteger = new BigInteger(input.getBytes());
      BigInteger inputInteger_encrypted = idea.encipher(inputInteger);

      Com.sendTo(0, inputInteger_encrypted.toString(16));
    }

  }