当前位置:文档之家› C语言实现凯撒加密解密

C语言实现凯撒加密解密


#include
#include
#include
#include

int jiami(FILE *fp1,FILE *fp2,char ch,char cn,int x)
{
do
{
/* read a char from the file */
ch = fgetc(fp1);
//printf("%d\n",ch);
if(ch==32){x=32-97;}
else{
/*change the ch*/
x = ch-'a'+3;}
if (x>25){x=x%26;}
/* display the character */
cn=x+97;
fputc(cn,fp2);
} while (ch!='#');
fclose(fp1);
fclose(fp2);
return 0;
}


int jiemi(FILE *fp1,FILE *fp2,char ch,char cn,int x)
{
do
{
/* read a char from the file */
ch = fgetc(fp1);
//printf("%d\n",ch);
if(ch==32){x=-91;}
else if(ch==38){x=-88;}
else{
/*change the ch*/
x = ch-'a'-3;}
if (x<0){x=x+26;}
/* display the character */
cn=x+97;
fputc(cn,fp2);
} while (ch!='&');
fclose(fp1);
fclose(fp2);
return 0;
}

int main(){
FILE *fp1,*fp2;
char ch,cn;
int x;
jiami(fopen("D:\\original.txt","r"),fopen("D:\\encrypt.txt","w"),ch,cn,x);
printf("end the jiami!\n");
jiemi(fopen("D:\\encrypt.txt","r"),fopen("D:\\de_original.txt","w"),ch,cn,x);
printf("end the jiemi!\n");

}

相关主题
文本预览
相关文档 最新文档