encryption - RSA Implementation in C# -
i trying implement rsa algorithm in c#. code below works when p , q small, not when trying replicate rsa-100 or greater p , q large.
for example when:
p = 61, q = 53, n = 3233, phi(n) = 3120, e = 17, d = 2753
once decrypted, correct original messsage. got these values rsa wikipedia page. code works other small values of p , q.
however, when using rsa-100 or greater, not original message. have tried using different values exponent (e) , made sure coprime phi(n) cannot correct result. missing simple/obvious?
thank in advance help!
//p , q rsa-100 //string p = "37975227936943673922808872755445627854565536638199"; //string q = "40094690950920881030683735292761468389214899724061"; string p = "61"; string q = "53"; //convert string biginteger biginteger rsa_p = biginteger.parse(p); biginteger rsa_q = biginteger.parse(q); //n = p * q biginteger rsa_n = biginteger.multiply(rsa_p, rsa_q); //phi(n) = (p-1)*(q-1) biginteger rsa_fn = biginteger.multiply((rsa_p - 1), (rsa_q - 1)); biginteger rsa_e = 17; //compute d biginteger rsa_d = biginteger.modpow(rsa_e, (rsa_fn - 1), rsa_fn); //encrypt message, in case 3007 //c = (3007^rsa_e) mod rsa_n biginteger c = biginteger.modpow(3007, rsa_e, rsa_n); //decrypt message, m should equal 3007 //m = (3007^rsa_d) mod rsa_n biginteger m = biginteger.modpow(c, rsa_d, rsa_n);
d=e^(phi(n)-1) mod phi(n) looks wrong me. either need d=e^(phi(phi(n))-1) mod phi(n), or use extended euclid.
Comments
Post a Comment