#include <stdio.h>
#include <string.h>
#include <windows.h>
#include<stdlib.h>
int g( char*);
int main()
{
char b[25] = { 0 };
int n,i;
int m = 0;
int o = 2;
printf("请输入移位数的值:");
scanf_s("%d", &n);//如果报错 请用scanf函数
getchar(); //去掉空格
while (o == 2)
{
printf("请输入明文:");
gets_s(b);
//getchar(); //去掉空格
int s;
s = g(b);
for (i = 0;i<s; i++) //获取密钥的长度
{
//把大写字母转化为小写字母
if (b[i] >= 'A' && b[i] <= 'Z')
{
b[i] += 32;
}
if (b[i] >= 'a' && b[i] <= 'z')
{
b[i] = ((b[i] - 'a') + n) % 26 + 'a';
o = 3;
}
if (b[i] < 'A' || b[i] > 'z')
{
printf("该程序仅支持大小写字母\n");
printf("请重新输入\n");
Sleep(1000);//延迟1s
system("cls");//清屏
//错误字符无论在什么位置都可以识别
o = 2;
break;
}
}
if(o==3)
{
printf("密钥:");
for (i = 0; i <s; i++)
{
printf("%c", b[i]);
}
}
}
getchar();
return 0;
}
int g( char *str)
{
int count = 0;
while (*str != '\0')
{
count++;
str++;
}
return count;
}
Last modification:December 12th, 2019 at 10:17 am
© The copyright belongs to the author