什么';我的CS50维格纳密码有什么问题?

什么';我的CS50维格纳密码有什么问题?,c,vigenere,cs50,C,Vigenere,Cs50,这件事我已经绕了几个小时了。它管理推荐测试的第一个单词(上午11点在公园见我)越过第一个空格,给m一个正确的字母,然后在结束前打印几个空格。非常感谢 #include <stdio.h> #include <cs50.h> #include <string.h> #include <ctype.h> int allstralpha(); int main(int argc, string argv[]) { string keyw =

这件事我已经绕了几个小时了。它管理推荐测试的第一个单词(上午11点在公园见我)越过第一个空格,给m一个正确的字母,然后在结束前打印几个空格。非常感谢

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>

int allstralpha();

int main(int argc, string argv[])
{
    string keyw = argv[1];
    if(argc == 2 && allstralpha(keyw))
    {
        string plaint = GetString();
        int c = 0;
        int kl = strlen(keyw);
        int k = 0;
        int p = 0;
        int j = 0;
        for(int i = 0, n = strlen(plaint); i < n; i++)
        {      
            if(isalpha(plaint[i]))
            {        
                if(isupper(keyw[j]))
                {
                    k = keyw[(j % kl)] - 65;
                    if(isupper(plaint[i]))
                    {
                        p = plaint[i] -65;
                        c = ((k + p) % 26) + 65;
                        printf("%c", (char) c);                     
                    }   
                    else if(islower(plaint[i]))
                    {
                        p = plaint[i] -97;
                        c = ((k + p) % 26) + 97;
                        printf("%c", (char) c);
                    }
                }
                else if(islower(keyw[j]))
                {   
                    k = keyw[(j % kl)] - 97;
                    if(isupper(plaint[i]))
                    {  
                        p = plaint[i] - 65;                                  
                        c = ((k + p) % 26) + 65;             
                        printf("%c", (char) c);

                    }
                    else if(islower(plaint[i]))
                    {
                        p = plaint[i] - 97; 
                        c = ((k + p) % 26) + 97;
                        printf("%c", (char) c);
                    }   
                }
                j++;    
            }
            else
            {
                printf("%c", (char) plaint[i]);
            }
        }       
    }
    else
    {
        printf("Sorry that is not a vaild parameter\n");
        return 1;
    }  
}
int allstralpha(string s)
{   
    for(int i = 0, n = strlen(s); i < n; i++)
    {
        if(!isalpha(s[i]))
        {
        return 0;
        }
    }
    return 1; 
}
#包括
#包括
#包括
#包括
int-allstralpha();
int main(int argc,字符串argv[])
{
字符串keyw=argv[1];
if(argc==2&&allstralpha(keyw))
{
string paint=GetString();
int c=0;
int kl=strlen(键w);
int k=0;
int p=0;
int j=0;
for(inti=0,n=strlen(哀怨);i
您的函数定义和声明不匹配。您应该声明
int-allstralpha(字符串s)

在主线的第一行:

int main(int argc, string argv[])
{
    string keyw = argv[1];
    ...
}
在访问
argv[1]

对于实际代码本身,您提供纯文本,但我看不到关键字

我使用来自的这些值进行测试:

Plaintext:  ATTACKATDAWN
Key:        LEMONLEMONLE
Ciphertext: LXFOPVEFRNHR
完成此操作的最低代码:

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, const char* argv[])
{
    const char *str = "Meet me at the park at eleven am";
    const char *key = "bacon";

    int keylen = strlen(key);
    int len = strlen(str);
    for (int i = 0, j = 0; i < len; i++)
    {
        int c = str[i];
        if (isalnum(c))
        {
            //int k = function of key and `j`...
            //offset k...
            if (islower(c))
            {
                c = (c - 'a' + k) % 26 + 'a';
            }
            else
            {
                c = (c - 'A' + k) % 26 + 'A';
            }
            j++;
        }
        putchar(c);
    }
    putchar('\n');
    return 0;
}
#包括
#包括
#包括
int main(int argc,const char*argv[]
{

const char*str=“上午11点在公园见我”; const char*key=“bacon”; int-keylen=strlen(键); int len=strlen(str); 对于(int i=0,j=0;i
请您详细说明输入和预期输出,不要过多地研究您的代码,让我问您:您是否为程序提供了将短语括在引号之间的参数?请显示您如何从命令行调用它。上午11点在公园与我会面Negh zf av huf pcfx bt gzrwep OZ截止到上午11点的英语应加密如下。对不起,现在在我的iphone上!如果我正确理解您的参数,我不会使用引号。请检查所有
keyw
访问。有几个地方你忘了做
(j%kl)
。我更新了答案。剩下的是家庭作业,你可以自己完成。
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, const char* argv[])
{
    const char *str = "Meet me at the park at eleven am";
    const char *key = "bacon";

    int keylen = strlen(key);
    int len = strlen(str);
    for (int i = 0, j = 0; i < len; i++)
    {
        int c = str[i];
        if (isalnum(c))
        {
            //int k = function of key and `j`...
            //offset k...
            if (islower(c))
            {
                c = (c - 'a' + k) % 26 + 'a';
            }
            else
            {
                c = (c - 'A' + k) % 26 + 'A';
            }
            j++;
        }
        putchar(c);
    }
    putchar('\n');
    return 0;
}