当输出看起来正确时,为什么这种ca撒加密是错误的?

库斯沃特

在过去的几天里,我一直在进行cs50项目“ Caesar”的工作,并设法使它达到视觉输出的目的,但是,每当我运行该课程要求我运行的check50时,它似乎一直在我遇到了多个无法直接找到的错误,因为在查看视觉输出时似乎是预期的。

这是由于在cs50 IDE中工作并遵循以下项目链接而产生的:

https://cs50.harvard.edu/x/2020/psets/2/caesar/

这是cs50 check50函数给出的结果:


>     :( encrypts "a" as "b" using 1 as key
>     expected "ciphertext: b\...", not "ciphertext: b"
>     Log
>     running ./caesar 1...
>     sending input a...
>     checking for output "ciphertext: b\n"...
>     
>     Expected Output:
>     ciphertext: b
>     Actual Output:
>     ciphertext: b
>     :( encrypts "barfoo" as "yxocll" using 23 as key
>     expected "ciphertext: yx...", not "ciphertext: yx..."
>     Log
>     running ./caesar 23...
>     sending input barfoo...
>     checking for output "ciphertext: yxocll\n"...
>     
>     Expected Output:
>     ciphertext: yxocll
>     Actual Output:
>     ciphertext: yxocll
>     :( encrypts "BARFOO" as "EDUIRR" using 3 as key
>     expected "ciphertext: ED...", not "ciphertext: ED..."
>     Log
>     running ./caesar 3...
>     sending input BARFOO...
>     checking for output "ciphertext: EDUIRR\n"...
>     
>     Expected Output:
>     ciphertext: EDUIRR
>     Actual Output:
>     ciphertext: EDUIRR
>     :( encrypts "BaRFoo" as "FeVJss" using 4 as key
>     expected "ciphertext: Fe...", not "ciphertext: Fe..."
>     Log
>     running ./caesar 4...
>     sending input BaRFoo...
>     checking for output "ciphertext: FeVJss\n"...
>     
>     Expected Output:
>     ciphertext: FeVJss
>     Actual Output:
>     ciphertext: FeVJss
>     :( encrypts "barfoo" as "onesbb" using 65 as key
>     expected "ciphertext: on...", not "ciphertext: on..."
>     Log
>     running ./caesar 65...
>     sending input barfoo...
>     checking for output "ciphertext: onesbb\n"...
>     
>     Expected Output:
>     ciphertext: onesbb
>     Actual Output:
>     ciphertext: onesbb
>     :( encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key
>     expected "ciphertext: ia...", not "ciphertext: ia..."
>     Log
>     running ./caesar 12...
>     sending input world, say hello!...
>     checking for output "ciphertext: iadxp, emk tqxxa!\n"...
>     
>     
>     <<

这是使用cs50库在C中完成的代码,以简化功能:

           //string validity
                     
            if (validity)
            {
                //prompt for plaintext
                string plaintext = get_string("Plaintext: ");
                printf("ciphertext: ");
                int n = strlen(plaintext);
                //calculate the encryption
                for (int i = 0; i < n; i++)
                {
                    if (isupper(plaintext[i]))
                    {
                        printf("%c", (plaintext[i] - 'A' + KEY)  % 26 + 'A');
                    }
                    else if (islower(plaintext[i]))
                    {
                       
                        printf("%c", (plaintext[i] - 'a' + KEY) % 26 + 'a');
                    }
                    else if( ispunct(plaintext[i]) || isspace(plaintext[i]))
                    {
                        printf("%c", plaintext[i]);
                    }
                }
                return 0;
            }
       }
    }

我相信问题出在上述代码的输出部分,我将非常感谢您的帮助

库斯沃特

答案来自“一些程序员伙计”的评论

原来,我必须在输出中打印最后一个'\ n'才能使其工作100%

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么输出看起来不同?

来自分类Dev

当通过tr“ \ n”“ \ n”`传递管道时,为什么`ls`的输出看起来不同?

来自分类Dev

当所有其他元素看起来正确时,为什么对fopen的调用失败?

来自分类Dev

为什么看起来像将int分配给int *时此分配是正确的?

来自分类Dev

为什么在使用初始化语法时未调用转换运算符,以及为什么clang错误消息看起来不正确?

来自分类Dev

C ++为什么当“ 100%看起来像匹配”时出现错误“没有匹配功能”?

来自分类Dev

C ++为什么当“ 100%看起来像匹配”时出现错误“没有匹配功能”?

来自分类Dev

为什么按钮看起来很奇怪?

来自分类Dev

为什么按钮看起来很奇怪?

来自分类Dev

为什么我的网站图标在我第一次访问时看起来不正确?

来自分类Dev

在这种简单情况下,为什么Matlab看起来比Python慢得多

来自分类Dev

动态重定向输出-在Linux中看起来不可能,为什么?

来自分类Dev

为什么我的Arc主题在Xubuntu上看起来不正确

来自分类Dev

为什么我的 Arc 主题在 Ubuntu 18.04 上看起来不正确?

来自分类Dev

为什么 fiddler 的 http 帖子正文显示为 0?这看起来正确吗?

来自分类Dev

pyplot输出看起来不正确

来自分类Dev

为什么在更改不同指令范围的模型但正确地限制(看起来是正确的)时,我的视图没有更新?

来自分类Dev

为什么在更改不同指令范围的模型但正确地限制(看起来是正确的)时,我的视图没有更新?

来自分类Dev

如果iPhone环境是wCompact-hCompact,为什么它看起来如此错误?

来自分类Dev

当HttpServer看起来足够时,为什么要在集成测试中使用HttpClient?

来自分类Dev

为什么zip文件看起来比源文件大,尤其是当它是文本时?

来自分类Dev

当HttpServer看起来足够时,为什么要在集成测试中使用HttpClient?

来自分类Dev

为什么字体有时在Mac OS X上看起来像“胖”?

来自分类Dev

在Windows Photo Viewer中预览时,为什么我的屏幕截图看起来很糟糕?

来自分类Dev

这些是物体吗?为什么当我打印它们时它们看起来像这样?

来自分类Dev

什么种族导致输出看起来不同?

来自分类Dev

意外的缩进错误,但缩进看起来正确

来自分类Dev

当输出为pdf时,为什么在R中添加到条形图中的点和线会移动(但在png中看起来很好)?

来自分类Dev

为什么我的图像在缩略图视图中看起来是横向的,但在打开时可以正确显示?

Related 相关文章

  1. 1

    为什么输出看起来不同?

  2. 2

    当通过tr“ \ n”“ \ n”`传递管道时,为什么`ls`的输出看起来不同?

  3. 3

    当所有其他元素看起来正确时,为什么对fopen的调用失败?

  4. 4

    为什么看起来像将int分配给int *时此分配是正确的?

  5. 5

    为什么在使用初始化语法时未调用转换运算符,以及为什么clang错误消息看起来不正确?

  6. 6

    C ++为什么当“ 100%看起来像匹配”时出现错误“没有匹配功能”?

  7. 7

    C ++为什么当“ 100%看起来像匹配”时出现错误“没有匹配功能”?

  8. 8

    为什么按钮看起来很奇怪?

  9. 9

    为什么按钮看起来很奇怪?

  10. 10

    为什么我的网站图标在我第一次访问时看起来不正确?

  11. 11

    在这种简单情况下,为什么Matlab看起来比Python慢得多

  12. 12

    动态重定向输出-在Linux中看起来不可能,为什么?

  13. 13

    为什么我的Arc主题在Xubuntu上看起来不正确

  14. 14

    为什么我的 Arc 主题在 Ubuntu 18.04 上看起来不正确?

  15. 15

    为什么 fiddler 的 http 帖子正文显示为 0?这看起来正确吗?

  16. 16

    pyplot输出看起来不正确

  17. 17

    为什么在更改不同指令范围的模型但正确地限制(看起来是正确的)时,我的视图没有更新?

  18. 18

    为什么在更改不同指令范围的模型但正确地限制(看起来是正确的)时,我的视图没有更新?

  19. 19

    如果iPhone环境是wCompact-hCompact,为什么它看起来如此错误?

  20. 20

    当HttpServer看起来足够时,为什么要在集成测试中使用HttpClient?

  21. 21

    为什么zip文件看起来比源文件大,尤其是当它是文本时?

  22. 22

    当HttpServer看起来足够时,为什么要在集成测试中使用HttpClient?

  23. 23

    为什么字体有时在Mac OS X上看起来像“胖”?

  24. 24

    在Windows Photo Viewer中预览时,为什么我的屏幕截图看起来很糟糕?

  25. 25

    这些是物体吗?为什么当我打印它们时它们看起来像这样?

  26. 26

    什么种族导致输出看起来不同?

  27. 27

    意外的缩进错误,但缩进看起来正确

  28. 28

    当输出为pdf时,为什么在R中添加到条形图中的点和线会移动(但在png中看起来很好)?

  29. 29

    为什么我的图像在缩略图视图中看起来是横向的,但在打开时可以正确显示?

热门标签

归档