本篇文章给大家谈谈c语言简单对字母加密,以及c语言简单字符加密对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
1、c语言字母加密?2、C语言指针:编写程序,对输入的一行小写字母进行加密处理。3、C语言题编程实现对键盘输入的大写英文字母进行加密。字母4、c语言对大写英文字母加密5、C语言怎么加密字符6、c语言如何字母加密
c语言字母加密?
按照你的要求编写的字母加密的C语言程序如下
(姓字母向后移两位,名字母向后移三位)
#includestdio.h
#includestring.h
int main(){
char src[30],result[]=””,ch[2]={‘\0’};
int i,j,len;
fgets(src,30,stdin);
len=strlen(src);
for(i=0;src[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=i;jlen;j++){
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;
}
C语言指针:编写程序,对输入的一行小写字母进行加密处理。
void encrypt(char *s)
{
while(*s)
{
if(*s=’a’*s=’z’)
*s=(*s+1-‘a’)%26+’a’;
s++;
}
}
#includestdio.h
int main()
{
char s[128];
printf(“请输入一个字符串:”);
scanf(“%s”,s);
encrypt(s);
printf(“加密后:%s\n”,s);
return 0;
}
C语言题编程实现对键盘输入的大写英文字母进行加密。字母
#includestdio.h
#includectype.h
int main()
{int i;
char s[200];
gets(s);
for(i=0;s[i];i++)
if(isalpha(s[i]))
{s[i]+=3;
if(s[i]%0x2026)s[i]-=26;
}
puts(s);
return 0;
}
c语言对大写英文字母加密
#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=0; istrlen(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之间的任意一位数)
C语言怎么加密字符
我没注意只要小写,我写的是大小写都可以的,另外附送输入验证。
#include stdio.h
#include string.h
int main()
{
char str[]=”00000″,str2[]=”00000″,*p=str,*p2=str2;
printf(“输入5个字母:”);
while(*p!=0)
{
scanf(“%c”,p);
if(*p==’\n’)
continue;
if(*p’A’||(*p’Z’*p’a’) || *p’z’) //输入验证,必须是字母
{
printf(“只能输入字母,请重新输入\n”);
p=str;
p2=str2;
fflush(stdin);//输入有错重新输入前清空缓冲区。fflush属于c扩展函数,正常使用没问题,如需在linux ggc上使用,考虑多次调用getchar函数来清空
}
else
{
*p2=(*p)+4;
if(*p290 *p297) //大写字母加4,最大位不超出
*p2=’A’+(*p2-90)-1;
if(*p2122) //小写字母加4,最大位不超出
*p2=’a’+(*p2-122)-1;
p2++;
p++;
}
}
printf(“原字符串为:%s\n加密后的字符串为:%s\n”,str,str2);
return 0;
}
c语言如何字母加密
//参考如下:
//先输入要加密的字母
//再输入往后移动几位的参数
//最后输出加密后的字母
//绝对简单,又符合要求int main()
#includestdio.h
{
char c;
scanf(“%c”,c);
int a;
scanf(“%d”,a);
printf(“%c\n”,c+a);
return 0;
}
关于c语言简单对字母加密和c语言简单字符加密的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。