#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语言 简单对字母进行加密
1、在我们的编辑页面输入以下代码。
㈢ C语言英文文本加密
#include "stdio.h"
#include <stdlib.h>
int main(int argc,char *argv[]){
FILE *fp,*fq;
int k,t;
fp=fopen("AAA12345678901.txt","w+");
if(!fp || (fq=fopen("tmp.txt","w"))==NULL){
printf("Failed to open the file and exit... ");
return 0;
}
printf("Please enter a short passage(letters+space+punctuation,'Enter' end)... ");
while((t=getchar())!=' ')//为文件输入内容
fputc(t,fp);
printf("Please enter the encryption key(int >0)... k=");
while(scanf("%d",&k)!=1 || k<1){//输入加密密钥并判断是否正确
printf("Input error, redo: ");
fflush(stdin);
}
rewind(fp);
while(t=fgetc(fp),!feof(fp))//加密
if(t>='A' && t<='Z')
fputc(((t-'A')+k)%26+'A',fq);
else if(t>='a' && t<='z')
fputc(((t-'a')+k)%26+'a',fq);
else
fputc(t,fq);
fclose(fp);//关闭原文件
fclose(fq);//关闭加密后的文件
remove("AAA12345678901.txt");//删除原文件
rename("tmp.txt","AAA12345678901.txt");//将加密后的文件更换为原文件名
printf(" ");
if(fp=fopen("AAA12345678901.txt","r")){
while((t=fgetc(fp))!=EOF)
printf("%c",t);
printf(" Encryption success! ");
}
else
printf(" Failed to open the encrypted file... ");
fclose(fp);
return 0;
}
代码格式和运行样例图片:
㈣ c语言字母加密
按照你的要求编写的字母加密的C语言程序如下
(姓字母向后移两位,名字母向后移三位)
#include<stdio.h>
#include<string.h>
int main(){
char src[30],result[]="",ch[2]={'