當前位置:首頁 » 密碼管理 » c加密字母

c加密字母

發布時間: 2023-01-21 20:57:39

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語言字母加密

按照你的要求編寫的字母加密的C語言程序如下

(姓字母向後移兩位,名字母向後移三位)

#include<stdio.h>

#include<string.h>

int main(){

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

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;j<len;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 ",result);

return 0;

}

③ C語言對字元進行加密

if(e>='A'&&e<='W')//
e+=3;
elseif(e>='X'&&e<='Z')
e-=23;
else
{
...//donotencryptordosomethingelse
}

④ 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之間的任意一位數)

⑤ C語言題編程實現對鍵盤輸入的大寫英文字母進行加密。字母

#include<stdio.h>
#include<ctype.h>
intmain()
{inti;
chars[200];
gets(s);
for(i=0;s[i];i++)
if(isalpha(s[i]))
{s[i]+=3;
if(s[i]%0x20>26)s[i]-=26;
}
puts(s);
return0;
}

⑥ 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;
}

熱點內容
編譯人行 發布:2025-08-27 16:53:45 瀏覽:584
電腦網路ip設置緩存 發布:2025-08-27 16:41:33 瀏覽:125
排隊叫號源碼 發布:2025-08-27 16:28:50 瀏覽:853
冪數運演算法則 發布:2025-08-27 16:25:37 瀏覽:695
為什麼魔法覺醒伺服器載入不出來 發布:2025-08-27 16:24:53 瀏覽:675
奕歌哪個配置最好看 發布:2025-08-27 16:12:39 瀏覽:603
美能達ftp掃描沒有文件 發布:2025-08-27 15:54:42 瀏覽:160
昂科威plus應該買哪個配置 發布:2025-08-27 15:52:52 瀏覽:947
fdisklinux 發布:2025-08-27 15:52:48 瀏覽:949
ipad連接id伺服器出錯要怎麼辦 發布:2025-08-27 15:48:15 瀏覽:727