Results 1 to 1 of 1
Thread: Modular Inverse Function issues.
- 10-28-2011, 08:36 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
Modular Inverse Function issues.
As some of you might have guessed, just a little implementation of the RSA algorithm. I can compute the public key fine, and in theory, the private key should be very easy and quick too compute, but it's not. The "modinverse()" function doesn't seem to be crunching out the correct numbers, because when I do (plaintext^publickey) mod n, I get a number that, when decrypted, doesn't equal the plaintext. I'm seriously confused guys, so can you dudes spot anything wrong here?Java Code:public class JavaApplication3 { public static void main(String[] args) { BigInteger p = new BigInteger(String.valueOf(3571)); BigInteger q = new BigInteger(String.valueOf(2063)); BigInteger n = p.multiply(q); BigInteger tOfN = new BigInteger(String.valueOf(p.subtract(new BigInteger("1")).multiply(q.subtract(new BigInteger("1"))))); Random randNum = new Random(); BigInteger publicKey = computePublicKey(randNum, tOfN); BigInteger privateKey = publicKey.modInverse(tOfN); System.out.println("Found Private Key. Val = " + privateKey); } public static BigInteger computePublicKey(Random randGen, BigInteger totientN) { boolean isSufficient = false; int temp; BigInteger tempPubKey; while(isSufficient == false) { temp = totientN.intValue(); tempPubKey = new BigInteger(String.valueOf(randGen.nextInt(temp))); System.out.println(tempPubKey); if((tempPubKey.compareTo(new BigInteger("1")) == 1) && (tempPubKey.compareTo(totientN)) == -1) { System.out.println("Found number in range."); if(tempPubKey.gcd(totientN).intValue() == 1) { System.out.println("Found GCD."); System.out.println("Found public Key. Val = " + tempPubKey.intValue()); return tempPubKey; } } } return new BigInteger("0"); } }
Similar Threads
-
Application questions (modular architecture / how to store config)
By Atikos in forum Advanced JavaReplies: 3Last Post: 12-05-2010, 04:43 PM -
Matrix Inverse
By TryingMybestInJava in forum New To JavaReplies: 4Last Post: 11-30-2010, 11:59 PM -
Inverse Cos
By dilpreet28 in forum Java AppletsReplies: 2Last Post: 06-11-2010, 12:23 AM -
Possible? Callback function passed as arguments to another function
By TreyAU21 in forum Advanced JavaReplies: 3Last Post: 12-04-2009, 03:08 PM -
inverse engineering
By Ed in forum JDBCReplies: 2Last Post: 07-02-2007, 07:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks