今天参考别人的修改了一个RSA的解密算法,但是RSA的加密算法始终没写对.谁可以帮助我根据我写的 RSADecrypt  ,修改出正确的 RSAEncrypt  算法吗???
这个程序是DELPHI写的以下是解密算法的过程.
Procedure RSADecrypt(E : String; Var exp, modb : TFGInt; Var D : String);
Var
    i, j, modbits: longint;
   EGInt, temp,temp1, temp2 : TFGInt;
   tempstr1, tempstr2, tempstr3 : String;
Begin
   FGIntToBase2String(modb, tempstr1);
   modbits := length(tempstr1);
   convertBase256to2(E, tempstr1);                                  //被加密数据转为2进制字符
   While copy(tempstr1, 1, 1) = '0' Do delete(tempstr1, 1, 1);      //循环删除tempstr1前的字符‘0’
   While (length(tempstr1) MOD (modbits * 2)) <> 0 Do tempstr1 := '0' + tempstr1;       //将删除‘0’后的tempstr1长度补齐为原始长度的整数乘2的倍(在字符前端加‘0’)
   j :=  length(tempstr1) DIV (modbits * 2) ;                       //tempstr1的长度除以 原始长度的两倍 = J
   tempstr2 := '';                                                  //清空 tempstr2
   For i := 1 To j Do                                               //以下循环 j 次                   // ******
   Begin
      tempstr3 := copy(tempstr1, 1, modbits);                       //将tempstr1字符中的 1 到modbits位复制到tempstr3
      While copy(tempstr3, 1, 1) = '0' Do delete(tempstr3, 1, 1);   //循环删除tempstr3 前面字符'0'
      If tempstr3 = '' Then exit;                                   //如果 tempstr3为空 跳出循环
      Base2StringToFGInt(tempstr3, EGInt);
      delete(tempstr1, 1, modbits);                                 //从tempstr1中删除1 到modbits位
      tempstr3 := copy(tempstr1, 1, modbits);                       //将tempstr1字符中的 1 到modbits位复制到tempstr3
      While copy(tempstr3, 1, 1) = '0' Do delete(tempstr3, 1, 1);   //循环删除tempstr3里的字符‘0’
      Base2StringToFGInt(tempstr3,temp);
      delete(tempstr1, 1, modbits);                                 //清空 tempstr1
      FGIntMontgomeryModExp(temp, exp, modb, temp1);
      FGIntDestroy(temp);                                           //清空 temp
      FGIntModInv(temp1, modb, temp);
      FGIntDestroy(temp1);                                          //清空 temp1
      FGIntMulMod(EGInt, temp, modb, temp2);
      FGIntDestroy(temp);                                           //清空 temp
      FGIntDestroy(EGInt);                                          //清空 EGInt
      tempstr3 := '';                                               //清空 tempstr3
      FGIntToBase2String(temp2, tempstr3);
      While (length(tempstr3) Mod (modbits - 1)) <> 0 Do tempstr3 := '0' + tempstr3;                  //在tempstr3的起始位补足‘0’直到tempstr3的长度为modbits-1的整数倍
      tempstr2 := tempstr2 + tempstr3;
      FGIntdestroy(temp2);                                          //清空 temp2
   End;                                                             //循环结束
   While (Not (copy(tempstr2, 1, 3) = '111')) And (length(tempstr2) > 3) Do delete(tempstr2, 1, 1);   //从tempstr2第一位开始删除字符,直到tempstr2的开头为'111',且tempstr2长度要大于3
   delete(tempstr2, 1, 3);                                          //删除tempstr2的前三位
   ConvertBase2To256(tempstr2, D);
End;