c語言字母加密
#include<stdio.h>
#include<string.h>
intmain()
{
charstr[]="00000",str2[]="00000",*p=str,*p2=str2;
printf("輸入5個字母:");
while(*p!=0)
{
scanf("%c",p);
if(*p=='
')
continue;
if(*p<'A'||(*p>'Z'&&*p<'a')||*p>'z')//輸入驗證,必須是字母
{
printf("只能輸入字母,請重新輸入
");
p=str;
p2=str2;
fflush(stdin);//輸入有錯重新輸入前清空緩沖區。fflush屬於c擴展函數,正常使用沒問題,如需在linuxggc上使用,考慮多次調用getchar函數來清空
}
else
{
*p2=(*p)+4;
if(*p2>90&&*p2<97)//大寫字母加4,最大位不超出
*p2='A'+(*p2-90)-1;
if(*p2>122)//小寫字母加4,最大位不超出
*p2='a'+(*p2-122)-1;
p2++;
p++;
}
}
printf("原字元串為:%s
加密後的字元串為:%s
",str,str2);
return0;
}
㈡ C語言對字元進行加密
if(e>='A'&&e<='W')//
e+=3;
elseif(e>='X'&&e<='Z')
e-=23;
else
{
...//donotencryptordosomethingelse
}
㈢ c語言輸入一個字母咋樣給他加密輸出然後跳到這個字母的第五位呢
咨詢記錄 · 回答於2021-10-13
㈣ c語言如何字母加密
//參考如下:
//先輸入要加密的字母
//再輸入往後移動幾位的參數
//最後輸出加密後的字母
//絕對簡單,又符合要求int main()
#include<stdio.h>
{
char c;
scanf("%c",&c);
int a;
scanf("%d",&a);
printf("%c
",c+a);
return 0;
}
㈤ C語言簡單字母加密
#include <stdio.h>
int main()
{
char ch;
printf("Enter the char be encrypted\n");
cin>>ch;
char c=(ch-'A'+3)%26+'a';
printf("%c",c);
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; i<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之間的任意一位數)