- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Vigenere 时遇到了一些问题,需要一些帮助。
/*
This program is a Vigenere Cipher.
I am Daniel of Asguard.
*/
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, string argv[])
{
string cipher; //this is a placeholder for the ciphered message.
char * key = argv[1];
int i = 0;
if (argc != 2) //this is meant to trigger if you don't enter the right call. So
{
printf("Please enter the cipher key when you call the program, such as './CaesarCipher 7'.\n"); //
return 1;
}
if (!isalpha(key[i])) //this is meant to trigger if you don't enter the right call. So
{
printf("Please only enter a word, no numerical numbers please."); //
return 1;
}
do
{
//printf("Please enter the message you would like to have converted, please. \n");
cipher = GetString();
}
while (cipher == NULL);
for (int i = 0, k = 0, n = strlen(cipher); i < n; i++, k++) //this is so the code knows to change only the characters in the sting cipher.
{
if (k >= strlen(key))
{
k = 0;
}
{
if (isupper(cipher[i]))
{
//cipher[i] = 'A' + (((cipher[i] - 'A') + (key[k]) - 'A') % 26);
cipher[i] = ((key[k] - 65) + (cipher[i] - 65)) % 26;
printf("%s\n", cipher);
}
else (islower(cipher[i]));
{
//cipher[i] = 'a' + (((cipher[i] - 'a') + (key[i]) - 'a') % 26);
cipher[i] = ((key[k] - 97) + (cipher[i] - 97)) % 26;
printf("%s\n", cipher);
}
}
}
printf("%s\n", cipher);
return 0;
}
当我这样做时,我的结果会出现奇怪的字符:⎽c▒⎺e┼├⎼▒┤└e⎼@☃de5▮:·/┬⎺⎼┐⎽⎻▒ce/⎻⎽e├2 $ └▒ ┐e ┴☃±e┼e⎼e 代表完成后我终端中的所有字母。
对于 BaZ,我的结果最终如下所示:
最佳答案
下面的代码按照 https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher 中的示例按预期工作
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void)
{
const char *cipher = "ATTACKATDAWN";
const char *key = "LEMON";
char *newkey;
char *p, *q;
int i =0;
int col, row;
if (strlen (key) < strlen (cipher))
{
printf ("key %s \n", key);
printf ("cipher \t%s \n", cipher);
newkey = malloc ( strlen (cipher) +1);
strcpy ( newkey, key);
p = (char *) (newkey + strlen (newkey)) ;
q = (char *) key;
i =strlen (key);
while (i < strlen (cipher) )
{
i++;
if (*q == 0)
q = (char *) key;
*p = *q;
p++;
q++;
}
*p = 0;
printf ("newk \t%s \n", newkey);
}
p = (char *) newkey;
q= (char *) cipher;
int a[1] ;
a[1] =0;
for (i =0 ; i < strlen(newkey); i++)
{
row = *p -65;
col = *q -65;
if (col+row > 26)
a [0] = 65 + col+row -26;
else
a [0] = 65 +col+row;
printf ("%s",(char *) &a[0]);
p++;
q++;
}
printf ("\n");
free( newkey);
/*L X F O P V E F R N H R*/
return 0;
}
关于CS50 Vigenere - 奇怪的图案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33459917/
我正在使用自定义的 uitableviewcell,并尝试重新创建一张活页纸作为背景。由于每个单元格都会根据文本量而增长,因此我需要为每个单元格的背景使用一个图案。但我对这些黑线有疑问,这让我发疯!
我已经解决这个问题 2 个小时了,似乎无法弄清楚如何按模式计数。 图案: 1-1-1 1-1-2 1-2-1 1-2-2 2-1-1 2-1-2 2-2-1 2-2-2 等等…… 最佳答案 我认为最简
我想尝试创建一个学习象棋应用程序作为学校项目。我的第一个计划是简单地让这个人工智能与自己进行较量,但要真正展示它是否成功,它需要能够展示它的进展情况。为了做到这一点,我希望它能够在 chess.com
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎偏离主题,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或 include a mini
以下函数返回什么? (就意义而言) int f(int n){ if(n == 0) return 0; else return n % 2 + f(n / 2) } 尝试运行代码,但
我有一个专栏A3:A71我希望填充值 =COUNTIF(B3:B71,B3) 第二个参数随每个单元格递增。 显然我不想每次都复制这个函数,所以我希望填充句柄能帮助我。然而,尽管它正确地增加了 COUN
我需要重复 svg 在水平方向 . 我的意思是,svg 比图案大,所以我需要它在剩下的任何空间上水平重复。 我希望主要图案出现在中心,这正是现在正在发生的事情。我只需要让它在两边都重复。 现在,我只
我需要重复 svg 在水平方向 . 我的意思是,svg 比图案大,所以我需要它在剩下的任何空间上水平重复。 我希望主要图案出现在中心,这正是现在正在发生的事情。我只需要让它在两边都重复。 现在,我只
请帮我完成作业。我想使用循环 C 语言生成这样的模式 X X X XXX XXXXX XXX X X X XXXXX X X X X X X XXXXX X XX X X X X X
c# 3.0 为我们提供了带有编译器生成的支持字段的 getter 和 setter - 这真的很棒,但很多时候您仍然需要使用支持字段。 在一个完美的世界(意见)中,你可以做类似的事情 class M
我正在创建一个 wordpress 主题,我正在尝试创建一个导航栏,其中每个 li 都有不同的背景颜色(例如,红色,然后是绿色,然后是蓝色)。然后在使用前三种颜色后,它会再次重复使用。 例如:
是否可以将 .svg 图案作为背景图像,svg 图案应调整为窗口宽度和高度。 最佳答案 这是可能的,但浏览器支持有限。 Webkit 往往具有最好的 SVG 支持,而 IE 最差。您可以使用 CSS
如何打印反Z图案? 普通 Z 模式的代码: int main() { int n; printf("Enter number of rows: "); scanf("%d", &n); for (in
我的图片中有重复的图案。我想根据相似的模式找到相似的图像。 图案由十字形、三角形、正方形组成,它们组合在一起形成由这些“原始形状”构成的更复杂的结构。例如,想象一个由三角形或六边形等组成的十字架。 这
是否可以在 SVG 填充中模拟以下 CSS? background-image: url(/* URL */); background-position: 50%; background-size:
这个问题在这里已经有了答案: How to make SVG image pattern fill move with object? (4 个答案) 关闭 1 年前。 我创建了这里看到的 svg
问题:存在关联键的表列表。有必要为每个表实现 CRUD + 一些关于表细节的功能(分页等)。麻烦:在每个表的每个功能实现中重复了大约 50% 的代码。问题:关于语言细节、优化/重构/使用类似代码模式的
尝试绘制在 x 轴上重复的背景。然而,图像放错了位置,当我调整窗口大小时,位于图案中的 View 将开始“移动”。 我做错了什么?目前正在做以下工作: [[NSColor colorWithPatte
Javascript 问题。 关于模式或表达,可能是重复的问题。 您可以使用下面的三个来获得一个对象。结果对象的工作原理相同。 当您使用繁重的 JavaScript Web 应用程序时,哪种模式最好?
是否可以使用 CSS 创建以下效果。我在 HTML 中只有一个 H2 元素,我对页面的 HTML 没有任何控制。我只能更改 CSS。 我用 :before 和 :after 尝试过,但到目前为止没有成
我是一名优秀的程序员,十分优秀!