求 column permutation cipher中断异常

C++语言 码拜 7年前 (2017-05-02) 1364次浏览
#include<stdio.h>
#include<string.h>
int main()
{
int i, j, l, k, m, num[30];
char key[30], plaintext[100], plaintext2[100], cipher[100];
printf(“please input the key\n”);
scanf_s(“%s”, key);
l = strlen(key);
for (i = 0; i < l; i++)
{
num[i] = 0;
for (j = 0; j < l; j++)
{
if (key[j] <= key[i])
{
num[i] = num[i] + 1;
}
if (key[j] == key[i] && j > i)
num[i] = num[i] – 1;
}
}
printf(“please input the plaintext\n”);
scanf_s(“%s”, plaintext);
k = strlen(plaintext);
i = 0;
for (m = k%l; m < l; m++)
{
plaintext[k + i] = “z”;
i++;
}
if (k%l == 0)
m = k / l;
else
m = k / l + 1;
printf(“加密:\n”);
for (i = 0; i < m; i++)
{
for (j = 0; j < l; j++)
{
cipher[i*l + j] = plaintext[i*l + num[j] – 1];
}
}
for (i = 0; i < l; i++)
{
for (j = 0; j < m; j++)
printf(“%c”, cipher[j*l + i]);
}
printf(“\n”);
printf(“解密:\n”);
for (i = 0; i < m; i++)
{
for (j = 0; j < l; j++)
{
plaintext2[i*l + num[j] – 1] = cipher[i*l + j];
}
}
plaintext2[(i – 1)*l + j] = “\0”;
printf(“%s\n”, plaintext2);
return 0;
}
解决方案

30

哪个地方异常?

30

scanf_s没用好,看看msdn吧,应该是
scanf_s(“%s”,key,sizeof(key));

scanf_s(“%s”,key,_countof(key));

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求 column permutation cipher中断异常
喜欢 (0)
[1034331897@qq.com]
分享 (0)