马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ~风介~ 于 2015-5-23 23:41 编辑
代码:/*
powered by Niko!!!
bbs.fishc.com
*/
#include <stdio.h>
#define N 3
void createMenu();
void Encryption();
void Decryption();
void Encryption_Block(char inputfile[20],char outputfile[20]);
void Decryption_Block(char inputfile[20],char outputfile[20]);
char Caecar(char c,int n);
void createMenu()
{
printf("1.Encrypt\n2.Decrypt\n3.Quit\n");
printf("Input Your Choice:");
}
void Encryption()
{
char infile[20],outfile[20];
printf("===Encryption===\n");
printf("Input Your Source File Name:");
scanf("%s",infile);
//printf("%s\n",infile);
printf("Input Your Target File Name:");
scanf("%s",outfile);
//printf("%s\n",outfile);
Encryption_Block(infile,outfile);
}
void Encryption_Block(char inputfile[20],char outputfile[20])
{
FILE *in,*out;
int ch;
if ((in = fopen(inputfile,"rb")) != NULL)
if ((out = fopen(outputfile,"wb")) != NULL)
while ((ch = fgetc(in)) != EOF)
{
ch = Caecar(ch,N);
fputc(ch,out);
}
else
printf("Can't Open Output File!");
else
printf("Can't Open Input File!");
printf("\nEncrypt is over!\n");
fclose(in);
fclose(out);
}
void Decryption()
{
char infile[20],outfile[20];
printf("===Decryption===\n");
printf("Input Your Source File Name:");
scanf("%s",infile);
//printf("%s\n",infile);
printf("Input Your Target File Name:");
scanf("%s",outfile);
//printf("%s\n",outfile);
Decryption_Block(infile,outfile);
}
void Decryption_Block(char inputfile[20],char outputfile[20])
{
FILE *in,*out;
int ch;
if ((in = fopen(inputfile,"rb")) != NULL)
if ((out = fopen(outputfile,"wb")) != NULL)
while ((ch = fgetc(in)) != EOF)
{
ch = Caecar(ch,(26-N));
fputc(ch,out);
}
else
printf("Can't Open Output File!");
else
printf("Can't Open Input File!");
printf("\nDecrypt is over!\n");
fclose(in);
fclose(out);
}
char Caecar(char c,int n)
{
//printf("%d",n);
if(c>='A'&&c<='Z')
{
return ('A'+(c-'A'+n)%26);
}
else if(c>='a'&&c<='z')
{
return ('a'+(c-'a'+n)%26);
}
else
return c;
}
int main (int argc, char *argv[])
{
char ch;
createMenu();
ch = getchar();
//putchar(ch);
if ('3' != ch)
{
//printf("Bingo!\n");
if ('1' == ch)
Encryption();
else
Decryption();
}
else
{
exit(0);
}
return 0;
}
|