/*************************************** ****************************************
* $ Header $
* $ Revision $
* $ Date $
*
* ===================================================== ========================================================
*
* Copyright (c) 2001-2004.
* All Rights Reserved.
*
* Created on 2004-11-15
**************************************** ***************************************/
Import java. Math. biginteger;
/**
* Todo enter the class information here.
*
* @ Author yanfei
*/
/*
* Modification history
* $ Log $
*/
Public class rsaalgorithm {
Biginteger modulus;
Biginteger publickey;
Biginteger privatekey;
Public rsaalgorithm (){
// Generation prime number by rsatool
// Firstprime = 1, 8531092198849658733790731600554882570012152789399913498991432728465552799732061900314704077553345030066920054082501510392030827356194179550613533833120011
// Secondprime = 11924164233834228789553347947559934849185846410886263275018134490056496194726414252409563040573266992224048791555973043496961395481558244111428543221720059
Modulus = new bigint ("101726144473065307136337870615470919343156117442809797759084430536209670790991552510812754477461878742757991641136682979130702060350988957821490188383976777417165191105548667246571012637458521780431579809518401391017216215682790968984090555280612303529196758248073861960100967926654874945078177551837993000649 ");
Publickey = new biginteger ("777777771 ");
// Privatekey = (x (firstPrime-1) (secondPrime-1) + 1)/publickey X is an integer.
Privatekey = new biginteger ("90174759107251056922810500448184130736176114745350210515099709962555046427810408233459605518228418589756487520725572479732405052968217872244415294457554090608096384694464961513226211645941929392277330122178360116753803241577778113257146900485635077056441559542883250804009040964580876711072978171708583360391 ");
}
Public String encrypt (string Str ){
Biginteger T = new biginteger (STR );
T = T. modpow (publickey, modulus );
System. Out. println ("encrypt STR is:" + T. tostring ());
Return T. tostring ();
}
Public String decrypt (string Str ){
Biginteger c = new biginteger (STR );
C = C. modpow (privatekey, modulus );
System. Out. println ("decrypt STR is:" + C. tostring ());
Return C. tostring ();
}
Public static void main (string [] ARGs ){
Rsaalgorithm RSA = new rsaalgorithm ();
String encryptstr = RSA. Encrypt ("1234343 ");
RSA. decrypt (encryptstr. tostring ());
}
}