Aiju
Gesperrt
Ich schreibe im Moment ein Programm zur Verschlüsselung mit RSA. (Nun ja eigentlich test ich erstmal die rsa-verschlüsselung aus)
Und da hab ich ein Prob: Zum Verschlüsseln muss ich fmod(pow(m, e), n) rechnen
m = 88 = 'X', e = 7, n = 187. Dass klappt ja noch, aber zum Entschlüsseln muss ich fmod(pow(c, d), n) rechnen und da hackts! (c = 11, d = 23, n = 187)
Hier erst mal der ganze Code des Experiments:
Wenn irgendwer den Code bzw. das Verschlüsselungsverfahren nicht kapiert, soll er ne Frage posten!
Mit PHP hab ich es schon hingekriegt: http://profjulius.cjb.cc
(n=187, e=7, p=11, q=17 o. was Anderes(bis auf n müssen das aber primzahlen sein) und k=Zahl die Verschlüsselt werden soll, c=Zahl die Entschlüsselt werden soll)
Weiß jemand wo der Fehler liegt?
EDIT: die vcl.h ist unwichtig
Und da hab ich ein Prob: Zum Verschlüsseln muss ich fmod(pow(m, e), n) rechnen
m = 88 = 'X', e = 7, n = 187. Dass klappt ja noch, aber zum Entschlüsseln muss ich fmod(pow(c, d), n) rechnen und da hackts! (c = 11, d = 23, n = 187)
Hier erst mal der ganze Code des Experiments:
Code:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <iostream>
#include <conio>
#include <math>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
typedef unsigned long int ulong;
typedef unsigned __int64 rsatyp;
rsatyp power(rsatyp x, rsatyp y)
{
rsatyp z = x;
for(rsatyp i=0;i<y;i++)
z *= z;
return z;
}
rsatyp rest(rsatyp x, rsatyp y)
{
long double z = (x * 1.0) / (y * 1.0);
z -= (rsatyp)z;
rsatyp r = z * y;
return r;
}
int main(int argc, char* argv[])
{
using namespace std;
rsatyp p = 11, q = 17, n = p * q, m = 'X', d, e = 7, c;
c = fmod(pow(m, e), n);
cout << "Verschlüsselte Botschaft: " << c << endl;
for(d=1;;d++)
{
rsatyp g = (p-1) * (q-1);
rsatyp x = (d * 7) % g;
if(x == 1)
break;
}
m = rest((rsatyp)pow(c, d), n);
cout << "Entschlüsselte Botschaft: " << m << endl;
getch();
return 0;
}
//---------------------------------------------------------------------------
Mit PHP hab ich es schon hingekriegt: http://profjulius.cjb.cc
(n=187, e=7, p=11, q=17 o. was Anderes(bis auf n müssen das aber primzahlen sein) und k=Zahl die Verschlüsselt werden soll, c=Zahl die Entschlüsselt werden soll)
Weiß jemand wo der Fehler liegt?
EDIT: die vcl.h ist unwichtig