凯撒密码代码c语言(凯撒密码编程题)

2023-02-17 23:18:33 密码用途 思思

c语言里的凯撒密码

#includestdio.h

#includestring.h

int main()

{

int i;int number;

char a[100];

scanf("%s",a);

number=strlen(a);

for(i=0;inumber;i++){

a[i]=a[i]+4;

}

for(i=0;inumber;i++){

printf("%c",a[i]);

return 0;

}

凯撒密码代码c语言(凯撒密码编程题) 第1张

凯撒密码 C语言

#includestdio.h

#includestring.h

void main ()

{

char str[100];

char str1[100];

printf("输入字符串:");

scanf("%s",str);

int len;

len=strlen(str);

for(int i=0;i<len;i++)

{

str1[i]=(str[i]-97+3)%26+97;

}

str1[len]='\0';

printf ("密文为:%s\n",str1);

}

凯撒密码的算法c语言的怎么实现啊?

凯撒密码是一种非常古老的加密方法,相传当年凯撒大地行军打仗时为了保证自己的命令不被敌军知道,就使用这种特殊的方法进行通信,以确保信息传递的安全。他的原理很简单,说到底就是字母于字母之间的替换。下面让我们看一个简单的例子:“baidu”用凯撒密码法加密后字符串变为“edlgx”,它的原理是什么呢?把“baidu”中的每一个字母按字母表顺序向后移3位,所得的结果就是刚才我们所看到的密文。

#include stdio.h

main()

{

char M[100];

char C[100];

int K=3,i;

printf("请输入明文M(注意不要输入空白串)\n");

gets(M);

for(i=0;M[i]!='\0';i++)

C[i]=(M[i]-'a'+K)%26+'a';

C[i]='\0';

printf("结果是:\n%s\n",C);

}

C语言!凯撒算法(只加密)的源代码

凯撒密码的原理是字母与字母之间的替换。例如26个字母都向后移动K位。若K等于2,则A用C代替,B用D代替,以此类推。

#include stdio.h

#include conio.h

int main(){

 int key;

 char mingma,mima;

 printf("\nPlease input the character:");

 scanf("%c",mingma); //输入明码

 printf("\nPlease input the key:");

 scanf("%d",key); //输入秘钥

 if((mingma='A')(mingma='Z'))

  mima='A'+(mingma-'A'+key)%26; //大写字母移位

 else if((mingma='a')(mingma='z'))

  mima='a'+(mingma-'a'+key)%26; //小写字母移位

 printf("\n The output is:%c",mima); //输出密码

 printf("\nFinished!\n");

 getch();

 return 0;

}

凯撒密码,C语言,求救!

#include stdio.h

#include string.h

int main()

{

int i = 0;

int len = 0;

char ch;

char buf[256] = {0};

char nor[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

char enc[26] = {'s','u','w','y','a','c','e','g','i','k','m','o','q','r','t','v','x','z','b','d','f','h','j','l','n','p'};

printf("Encode or Decode: ");

scanf("%c",ch);

printf("please input your string: ");

fflush(stdin);

gets(buf);

len = strlen(buf);

switch (ch)

{

case 'e':

case 'E':

for (i=0;ilen;i++)

{

buf[i] = enc[buf[i] - 'a'];

}

break;

case 'd':

case 'D':

for (i=0;ilen;i++)

{

buf[i] = nor[i];

}

break;

default:

printf("wrong input!\n");

}

printf("%s\n",buf);

return 0;

}