?? rsa.c
字號(hào):
/*****************************************************************************
* *
* --------------------------------- rsa.c -------------------------------- *
* *
*****************************************************************************/
#include "encrypt.h"
/*****************************************************************************
* *
* -------------------------------- modexp -------------------------------- *
* *
*****************************************************************************/
static Huge modexp(Huge a, Huge b, Huge n) {
Huge y;
/*****************************************************************************
* *
* Compute pow(a, b) % n using the binary square and multiply method. *
* *
*****************************************************************************/
y = 1;
while (b != 0) {
/**************************************************************************
* *
* For each 1 in b, accumulate y. *
* *
**************************************************************************/
if (b & 1)
y = (y * a) % n;
/**************************************************************************
* *
* Square a for each bit in b. *
* *
**************************************************************************/
a = (a * a) % n;
/**************************************************************************
* *
* Prepare for the next bit in b. *
* *
**************************************************************************/
b = b >> 1;
}
return y;
}
/*****************************************************************************
* *
* ----------------------------- rsa_encipher ----------------------------- *
* *
*****************************************************************************/
void rsa_encipher(Huge plaintext, Huge *ciphertext, RsaPubKey pubkey) {
*ciphertext = modexp(plaintext, pubkey.e, pubkey.n);
return;
}
/*****************************************************************************
* *
* ----------------------------- rsa_decipher ----------------------------- *
* *
*****************************************************************************/
void rsa_decipher(Huge ciphertext, Huge *plaintext, RsaPriKey prikey) {
*plaintext = modexp(ciphertext, prikey.d, prikey.n);
return;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -