繁体   English   中英

为什么我的 Caesar Cipher 程序不能按照我的代码运行? 代码编译,但不加密明文

[英]Why doesn't my Caesar Cipher program work according to my code? The code compiles, but does not encipher plaintext

我很好奇为什么这段代码可以正确编译,但只返回从用户那里获取的明文。 即使代码中的算法如此说明,它也不会对明文进行加密。

#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在明文读入后永远不会改变。 我建议仔细看看你的作业顺序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM