| NoTeefy | That‘s why I prefer Libraries for such stuff |
| Bread | An RSA class |
| NoTeefy | there‘s no need to reinvent the wheel for the same formula 😄 |
| NoTeefy | But yeah, you gotta write it on your own if you‘re not allowed to use external libs |
| Bread | You say a message, private keys, etc and then it will be encrypted |
| NoTeefy | Nice 😃 |
| Bread | Yeah of course not, it's a task D: |
| Bread | But I did well |
| NoTeefy | Fürs Studium oder die Schule? |
| Bread | Wow |
| Bread | Da übersetze ich die ganze Zeit den Text xD |
| Bread | Schule |
| NoTeefy | Fand ich ganz amüsant. Dein Code hat deine Herkunft verraten 😝🙈 |
| Bread | ```java
public class RSA
{
public void dBerechnen(int e, int phi) {
//Globale Variablen
int eslashphi=0;
int emodphi = 1;
int a = 0; //a muss 0 und b muss 1 sein.
int b = 1;
int aalt;
int balt;
int phiFallsDNegativ = phi;
int d;
Stack eslashphiWerte = new Stack<>();
//Solange rechnen, bis e mod Phi = 0 ist.
while(emodphi!=0) {
System.out.println("e ist "+e);
System.out.println("Phi ist "+phi);
//Wie oft passt Phi in e ist e/Phi, die Reste davon bilden e mod Phi
eslashphi=e/phi;
System.out.println("e/Phi ist "+eslashphi);
eslashphiWerte.push(eslashphi);
emodphi=(e % phi);
System.out.println("e mod Phi ist "+emodphi);
//Das alte Phi wird zu e, das alte e mod Phi wird zu Phi
e=phi;
phi=emodphi;
System.out.println();
}
eslashphiWerte.pop(); // es soll ja nicht das alte e/phi, sondern das, der aktuellen Reihe genommen werden
//das alte b wird zu a, das neue b ist = das alte a - (eslashphi aus der selben Reihe, wie das neue b * das alte b)
while(!eslashphiWerte.isEmpty()) {
System.out.println("");
aalt=a;
balt=b;
a=b;
b=aalt-(eslashphiWerte.top()*balt);
eslashphiWerte.pop();
System.out.println("Das neue a ist "+a);
System.out.println("Das neue b ist "+b);
}
//Entweder ist d nun positiv oder negativ
d=a+phiFallsDNegativ;
System.out.println();
System.out.println(a>0 ? "Der Entschlüsselungsexponent d ist "+a : "Der Entschlüsselungsexponent d ist negativ. Daher ist es laut dem Gesetz d>0 inkorrekt. Das korrekte d ist daher: "+d);
}
``` Ohne deine Lösung |
| Bread | das glaube ich :D |
| Bread | Bin müde und hab wahrscheinlich vergessen ein paar Sachen zu übersetzen D; |
| NoTeefy | Oha, bei uns durften wir nie so geile Sachen machen; als ich noch in der Schule war 😦 |
| NoTeefy | Eigentlich wars nur ein Ich 😄 |
| Bread | Da hätte ich ja direkt Deutsch schreiben können :D |
| Bread | Naja ist auch nicht direkt vorgeschrieben |