导航:首页 > 文档加密 > 字符加密英语字母c语言

字符加密英语字母c语言

发布时间:2023-01-05 05:02:08

1. C语言 字符串加密

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
intmain(void)
{
charc[100];
intk;
intlen,i,temp;

scanf("%s",c);
scanf("%d",&k);

len=(int)strlen(c);
k=k%26;

for(i=0;i<len;i++)
{
if(c[i]>='a'&&c[i]<='z')
{
if(c[i]+k>'z')
{
temp='z'-c[i];
temp=k-temp-1;
c[i]='a'+temp;
}
else
{
c[i]+=k;
}
}
elseif(c[i]>='A'&&c[i]<='Z')
{
if(c[i]+k>'Z')
{
temp='Z'-c[i];
temp=k-temp-1;
c[i]='A'+temp;
}
else
{
c[i]+=k;
}
}
else
{
/*donothing*/
}
}

printf("%s ",c);

return0;
}

2. 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;

}

代码格式和运行样例图片:

3. 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;

}

4. 用C语言编程实现对键盘输入的英文名句子进行加密

#include<stdio.h>

void main()

{

char str1[256],str2[256],*p,*q;
int x;
gets(str1); p=str1; q=str2;
while ( *p )
{ if ( (*p)>='A' && (*p)<='Z' )
{ x=(*p)-'A';
x++; (*q)=x%26+'A'; q++;
x++; (*q)=x%26+'A'; q++;
x++; (*q)=x%26+'A';
}
else if ( (*p)>='a' && (*p)<='z' )
{ x=(*p)-'a';
x++; (*q)=x%26+'a'; q++;
x++; (*q)=x%26+'a'; q++;
x++; (*q)=x%26+'a';
}
else (*q)=(*p);
p++; q++;
}
(*q)=0; printf("%s ",str2);}

}

5. 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;
}

6. 用C语言加密 字母信息加密字母按字母表,进行对调,大小写不变(a-z,b-y,c-x,…) 急求答案!

//VC++6.0下进行编译
#include <stdio.h>
#define N 25

void jiami(char namea[256])
{
FILE *fp_jiami,*fp_file2;
char c;
fp_jiami=fopen(namea,"rb");
fp_file2=fopen("file2.plg","wb");
while(EOF!=(fscanf(fp_jiami,"%c",&c)))
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
c=c+N;
if (!((c>='A'&&c<='Z')||(c>='a'&&c<='z')))c=c-26;
if(c>='a'&&c<='z')c=c-32;
}
fprintf(fp_file2,"%c",c);
}
fclose(fp_file2);
fclose(fp_jiami);
}

void jiemi(char en_name[256])
{
FILE *fp_jiemi,*fp_file3;
char c;
fp_jiemi=fopen(en_name,"rb");
fp_file3=fopen("file3.plg","wb");
while(EOF!=(fscanf(fp_jiemi,"%c",&c)))
{
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
c=c-N;
if (!((c>='A'&&c<='Z')||(c>='a'&&c<='z')))c=c+26;
if(c>='A'&&c<='Z')c=c+32;
}

fprintf(fp_file3,"%c",c);
}
fclose(fp_file3);
fclose(fp_jiemi);

}

int main()
{
char name[256];
int n;

printf("输入你要操作的TXT文本:");
gets(name);

printf("\n请选择需要进行的操作:\n");
printf(" 1:加密 2:解密 \n");
printf("输入你的选择:");

scanf("%d",&n);
switch(n) {
case 1:{jiami(name);printf("\t加密成功!!\n\n");
break;}
case 2:{jiemi(name);printf("\t解密成功!!\n\n");
break;}
default:{printf("输入操作不存在!");}
}

return 0;

}

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

8. 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之间的任意一位数)

9. C语言对字符进行加密

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

10. 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语言相关的资料

热点内容
加密货币容易被盗 浏览:82
苹果平板如何开启隐私单个app 浏览:704
空调压缩机一开就停止 浏览:528
如何下载虎牙app 浏览:847
日语年号的算法 浏览:955
dev里面的编译日志咋调出来 浏览:298
php函数引用返回 浏览:816
文件夹和文件夹的创建 浏览:259
香港加密货币牌照 浏览:838
程序员鼓励自己的代码 浏览:393
计算机网络原理pdf 浏览:752
吃鸡国际体验服为什么服务器繁忙 浏览:94
php中sleep 浏览:490
vr怎么看视频算法 浏览:86
手机app如何申报个人所得税零申报 浏览:694
如何截获手机app连接的ip 浏览:332
冰箱压缩机是否需要电容 浏览:346
python列表每一行数据求和 浏览:276
自己有一台服务器可以玩什么 浏览:658
社会学波普诺pdf 浏览:585