最近要準備某個考試,沒時間更了,只能大概寫一下了。這個新手可能不好理解,但是我希望大家都能理解。Orz,我將埃特巴什碼的加解密分成了三步。
1、單個字母的加解密(僅能處理小寫)
#include<stdio.h> //標準輸入輸出頭文件,沒有它就無法使用scanf和printf
int main(){
char c;
scanf("%c",&c);
printf("%c",'z'-(c-'a')); //理解這里的ACSII碼
return 0;
}
2、單個字母的加解密(能處理大小寫)
#include<stdio.h>
#include<ctype.h> //tolower函數(shù)將字符全部轉換為小寫
int main(){
char c;
scanf("%c",&c);
printf("%c",'z'-(tolower(c)-'a'));
return 0;
}
3、字符串的加解密處理
#include<stdio.h>
#include<ctype.h>
int main(){
int i=0;
char c[100];
scanf("%s",c);
while(c[i]!='\0'){ // 考慮為什么是\0
printf("%c",'z'-(tolower(c[i])-'a'));
i++;
}
return 0;
}
運行示例