c语言字母加密?

c语言字母加密?,第1张

按照你的要求编写的字母加密的C语亮脊言程序如下

(姓字母向后移两位,名字母向后移三位敬斗渗)

#include<stdio.h>

#include<string.h>

int main(){

char src[30],result[]="",ch[2]={'\0'}

int i,j,len

fgets(src,30,stdin)

len=strlen(src)

for(i=0src[i]!=' 'i++){

if('a'<=src[i] &&src[i]<='z'){

ch[0]=(char)(((src[i]-'a')+2)%26+'a')

strcat(result,ch)

}else if('A'<=src[i] &&src[i]<='Z'){

ch[0]=(char)(((src[i]-'A')+2)%26+'A')

strcat(result,ch)

}else{

ch[0]=src[i]

strcat(result,ch)

}

}

for(j=ij<lenj++){

if('a'<=src[j] &销誉&src[j]<='z'){

ch[0]=(char)(((src[j]-'a')+3)%26+'a')

strcat(result,ch)

}else if('A'<=src[j] &&src[j]<='Z'){

ch[0]=(char)(((src[j]-'A')+3)%26+'A')

strcat(result,ch)

}else{

ch[0]=src[j]

strcat(result,ch)

}

}

printf("%s\n",result)

return 0

}

void encrypt(char *s)

{

while(*s)

{

if(*s>='a'&&*s<='z')

*s=(*s+1-'则腊a')%26+'罩侍a'

s++

}

}

#include<stdio.h>

int main()

{

char s[128]

printf("请输入物盯吵一个字符串:")

scanf("%s",s)

encrypt(s)

printf("加密后:%s\n",s)

return 0

}

#include <stdio.h>

#include <string.h>

int main()

{

char passwd[100],encrypted[100]

int i,j,k,t,move

while(1)

{

printf("Enter message to be encrypted:")

gets(passwd)

move=3

for(i=0i<strlen(passwd)i++)

{

if(passwd[i] >= 'A' &&passwd[i] <= 'Z')

{

passwd[i] = ((passwd[i]-'A')+move)%26+'A'

} else if(passwd[i] >= 'a' &&passwd[i] <= 'z')

{

passwd[i] = ((passwd[i]-'a')+move)%26+'a'

}

}

printf("%s"滚枝,passwd)

printf("\n")

}

return 0

}

这大掘敏道题实际上就是C语言版的凯撒加密(字母往后面移动1-25之间的任意一位数)散州


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12534173.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存