用C语言加密 字母信息加密字母按字母表,进行对调,大小写不变(a-z,b-y,c-x,…) 急求答案!
4个回答
展开全部
//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;
}
#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;
}
展开全部
#include <stdio.h>
#include <string.h>
int main()
{
char *word;
int len,i;
while(gets(word))
{
len=strlen(word);
for(i=0;i<len;i++)
if(word[i]>='a'&&word[i]<='z') putchar('a'+'z'-word[i]); //任何字母和它对应的字母的ASIC码之和是不变的
else if(word[i]>='A'&&word[i]<='Z') putchar('A'+'Z'-word[i]);
putchar('\n');
}
return 0;
}
#include <string.h>
int main()
{
char *word;
int len,i;
while(gets(word))
{
len=strlen(word);
for(i=0;i<len;i++)
if(word[i]>='a'&&word[i]<='z') putchar('a'+'z'-word[i]); //任何字母和它对应的字母的ASIC码之和是不变的
else if(word[i]>='A'&&word[i]<='Z') putchar('A'+'Z'-word[i]);
putchar('\n');
}
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
void encrypt(char* c)
{
while(*c)
{
if(*c>='a'&&*c<='z')*c=('a'+'z'-*c);
else if(*c>='A'&&*c<='Z')*c=('A'+'Z'-*c);
c++;
}
}
int main()
{
char a[]="Hello, world!\n";
encrypt(a);
printf("%s",a);
encrypt(a);
printf("%s",a);
}
void encrypt(char* c)
{
while(*c)
{
if(*c>='a'&&*c<='z')*c=('a'+'z'-*c);
else if(*c>='A'&&*c<='Z')*c=('A'+'Z'-*c);
c++;
}
}
int main()
{
char a[]="Hello, world!\n";
encrypt(a);
printf("%s",a);
encrypt(a);
printf("%s",a);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
void main()
{
int c;
while(c = getchar())
97<=c&&c<=122?putchar(219-c):65<=c&&c<=90?putchar(155-c):putchar(c);
}
-------------------------
仅加密字母若输入其他字符不会改变
void main()
{
int c;
while(c = getchar())
97<=c&&c<=122?putchar(219-c):65<=c&&c<=90?putchar(155-c):putchar(c);
}
-------------------------
仅加密字母若输入其他字符不会改变
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询