C语言中的简单RSA
任务是编写一个可以用RSA加密和解密消息的程序 我开始写它,但在刚开始的时候,当我想决定是加密(e)还是解密(d)时,程序不接受我的e。错在哪里 我该怎么继续?我想我没有得到rsa系统 谢谢大家!C语言中的简单RSA,c,encryption,rsa,C,Encryption,Rsa,任务是编写一个可以用RSA加密和解密消息的程序 我开始写它,但在刚开始的时候,当我想决定是加密(e)还是解密(d)时,程序不接受我的e。错在哪里 我该怎么继续?我想我没有得到rsa系统 谢谢大家! #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> /* Simple RSA: encrypt text using a secure crypto
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
/* Simple RSA:
encrypt text using a secure cryptographic function that makes decryption
impossible unless the recipient has the corresponding key for decryption.
*/
unsigned long long int p;
unsigned long long int q;
unsigned long long int N; // modulus for encryption and decryption
unsigned int e;
unsigned long long int d;
unsigned long long int phi;
unsigned int c;
unsigned int m;
signed int s;
signed int t;
unsigned long long int e_or_d;
int i = 0;
int main () {
/* Ask the user about the numbers N and e */
printf("Enter N: ");
scanf("%u", &N);
getchar();
printf("Enter e: ");
scanf("%u", &e);
getchar();
/* Ask the user if he wants to decrypt or encrypt a message */
while(1) {
printf("Encrypt or Decrypt [e/d]? ");
scanf("%2c", &e_or_d);
getchar();
if(e_or_d != e | d) {
return 0;
}
if(e_or_d = e) {
printf("Enter message: \n");
scanf("%u", &m);
getchar();
for (i = 0; i < m; i++) {
N = p*q;
phi = (p-1)*(q-1);
}
if(N < 0) {
return 0;
}
else if(N = 0) {
return 1;
}
else if(N = 1) {
return ?
}
return 0;
}
if(e_or_d = d) {
printf("Enter d: \n");
scanf("%u", &d);
getchar();
return 0;
}
return 0;
}
return 0;
}
#包括
#包括
#包括
#包括
/*简单RSA:
使用进行解密的安全加密函数加密文本
不可能,除非收件人有相应的密钥进行解密。
*/
无符号长整型p;
无符号长整型q;
无符号长整型N;//加解密模
无符号整数e;
无符号长整型d;
无符号长整型φ;
无符号整数c;
无符号整数m;
签名整数s;
符号整数t;
无符号长整型或长整型;
int i=0;
int main(){
/*询问用户有关数字N和e的信息*/
printf(“输入N:”);
scanf(“%u”、&N);
getchar();
printf(“输入e:”);
scanf(“%u”、&e);
getchar();
/*询问用户是否要解密或加密消息*/
而(1){
printf(“加密或解密[e/d]?”;
扫描频率(“%2c”、&e\u或\u d);
getchar();
如果(e|u或| d!=e|d){
返回0;
}
如果(e_或d=e){
printf(“输入消息:\n”);
scanf(“%u”、&m);
getchar();
对于(i=0;i
我不确定你想要实现什么,我可能误解了这一点。但在这里:
if(e_or_d != e | d) {
return 0;
}
这:是按位或。我相信你的意思是:
if ((e_or_d != 'e') && (e_or_d) != 'd'))
return 0;
要检查输入是char
'e'
还是char'd'
是,谢谢!我忘记了'并且以错误的方式做了'或',但是我没有工作,尽管我纠正了我的错误。..if((e_或_d!='e')|(e_或_d!='d')){return 0;}if(e_或_d='e'){printf(“输入消息:\n”);scanf(%u,&m);getchar();for(I=0;i@Tina:编辑答案。