编码caesar加密代码需要两次密钥?
我实现了这个算法,但似乎没有抓住所有细节,因为当我运行程序时,它要求输入两次密钥编码caesar加密代码需要两次密钥?,c,algorithm,cs50,caesar-cipher,C,Algorithm,Cs50,Caesar Cipher,我实现了这个算法,但似乎没有抓住所有细节,因为当我运行程序时,它要求输入两次密钥 #包括 #包括 #定义大小1024 字符文本[大小]; int text_2[大小]; int键; int编码器(字符文本[大小]){ printf(“明文:\n”); 获取(文本); 对于(int i=0;i
#包括
#包括
#定义大小1024
字符文本[大小];
int text_2[大小];
int键;
int编码器(字符文本[大小]){
printf(“明文:\n”);
获取(文本);
对于(int i=0;i0){
printf(“很好,现在输入一个单词对其进行加密\n”);
获取(text);//此步骤是将文本传递到编码器函数所必需的。
编码器(文本);
放置(文本);
}否则{
printf(“Yeuch!!\n”);
}
}
输出的一个示例是:
enter the key:
2 //I press 2 and nothing happens, then it asks for it again, hence why I have two 2's
2
nice!, now enter a word to encrypt it
plaintext:
a
c
Process finished with exit code 0
%d
忽略换行符-stdin中的换行符将保留,如果格式为%d\n
,则需要两个回车键
if子句中的获取(文本)
删除换行符-您只需将格式更改为%d
解决方案:
intmain(){
printf(“输入密钥:\n”);
scanf(“%d”和键)(&key);
如果(键<26&&键>0){
printf(“很好,现在输入一个单词对其进行加密\n”);
获取(文本);//此步骤是将文本传递到编码器所必需的
//功能。
编码器(文本);
放置(文本);
}否则{
printf(“Yeuch!!\n”);
}
}