当前位置:网站首页 > 加密货币 > 正文

凯撒密码加密(凯撒密码加密过程)



凯撒密码

解密

程序(C语言)

2009年09月30日 星期三 13:21

1、程序结构化,用函数分别

实现

2、对文件的

加密

解密

输出到文件

#include

#include

void menu()/*菜单,1.

加密

2.

解密

3.退出*/

{

clrscr();

printf("

===============================================================================");

printf("

1.Encrypt the file");

printf("

2.Decrypt the file");

printf("

3.Quit

");

printf("===============================================================================

");

printf("Please select a item:");

return;

}

char encrypt(char ch,int n)/*

加密

函数,把字符向右循环移位n*/

{

while(ch>='A'&&ch='a'&&ch<='z')

{

return ('a'+(ch-'a'+n)%26);

}

return ch;

}

main()

{

int i,n;

char ch0,ch1;

FILE *in,*out;

char infile[10],outfile[10];

textbackground(RED);

textcolor(LIGHTGREEN);

clrscr();

menu();

ch0=getch();

while(ch0!='3')

{

if(ch0=='1')

{

clrscr();

printf("

Please input the infile:");

scanf("%s",infile);/*输入需要

加密

的文件名*/

if((in=fopen(infile,"r"))==NULL)

{

printf("Can not open the infile!

");

printf("Press any key to exit!

");

getch();

exit(0);

}

printf("Please input the key:");

scanf("%d",&n);/*输入

加密

密码*/

printf("Please input the outfile:");

scanf("%s",outfile);/*输入

加密

后文件的文件名*/

if((out=fopen(outfile,"w"))==NULL)

{

printf("Can not open the outfile!

");

printf("Press any key to exit!

");

fclose(in);

getch();

exit(0);

}

while(!feof(in))/*

加密

*/

{

fputc(encrypt(fgetc(in),n),out);

}

printf("

Encrypt is over!

");

fclose(in);

fclose(out);

sleep(1);

}

if(ch0=='2')

{

clrscr();

printf("

Please input the infile:");

scanf("%s",infile);/*输入需要

解密

的文件名*/

if((in=fopen(infile,"r"))==NULL)

{

printf("Can not open the infile!

");

printf("Press any key to exit!

");

getch();

exit(0);

}

printf("Please input the key:");

scanf("%d",&n);/*输入

解密

密码(可以

加密

时候的密码)*/

n=26-n;

printf("Please input the outfile:");

scanf("%s",outfile);/*输入

解密

后文件的文件名*/

if((out=fopen(outfile,"w"))==NULL)

{

printf("Can not open the outfile!

");

printf("Press any key to exit!

");

fclose(in);

getch();

exit(0);

}

while(!feof(in))

{

fputc(encrypt(fgetc(in),n),out);

}

printf("

Decrypt is over!

");

fclose(in);

fclose(out);

sleep(1);

}

clrscr();

printf("

Good Bye!

");

sleep(3);

getch();

}

到此这篇凯撒密码加密(凯撒密码加密过程)的文章就介绍到这了,更多相关内容请继续浏览下面的相关 推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • 怎么破解pdf文件权限密码忘了(破解pdf权限加密)2025-09-26 20:45:07
  • u盘怎么设置密码加密文件(u盘怎么设置密码文件夹)2025-09-26 20:45:07
  • 博图v15程序加密(博途程序加密)2025-09-26 20:45:07
  • u盘设置密码加密方法(u盘设置密码加密方法有哪些)2025-09-26 20:45:07
  • 破解doc加密文件(破解doc加密文件的网站)2025-09-26 20:45:07
  • 密码加密是什么意思(密码加密是怎么实现的)2025-09-26 20:45:07
  • 加密密码忘了怎么解除(手机加密密码忘了怎么解除)2025-09-26 20:45:07
  • ini配置文件加密(如何配置ini文件)2025-09-26 20:45:07
  • ini文件乱码加密破解(ini文件编码)2025-09-26 20:45:07
  • 密码加密(摩斯密码加密)2025-09-26 20:45:07
  • 全屏图片