[英]Why doesn't my Caesar Cipher program work according to my code? The code compiles, but does not encipher plaintext
I am curious why this code compiles correctly but only returns the plaintext taken from the user.我很好奇为什么这段代码可以正确编译,但只返回从用户那里获取的明文。 It does not encipher the plaintext even though the algorithm in the code states so.
即使代码中的算法如此说明,它也不会对明文进行加密。
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main(void)
{
string message=get_string("Enter a message to encrypt: \n");
int key=get_int("Enter a key to encrypt the message: \n");
char m[strlen(message)];
strcpy(m, message);
for(int i=0; i<strlen(message); i++)
{
char letter=m[i];
if(isalpha(m[i])||isupper(m[i])||islower(m[i]))
{
if(letter>='a'&&letter<='z')
{
letter=letter+key;
if(letter>'z')
{
letter=letter-'z'+'a'-1;
letter=m[i];
}
letter=m[i];
}
else if(letter>='A'&&letter<='Z')
{
letter=letter+key;
if(letter>'Z')
{
letter=letter-'Z'+'A'-1;
letter=m[i];
}
letter=m[i];
}
}
printf("%c", m[i]);
}
printf("\n");
return 0;
}
m
is never changed after the plaintext is read into it. m
在明文读入后永远不会改变。 I suggest taking a closer look at the order of your assignments.我建议仔细看看你的作业顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.