易位加密算法实现

该博客介绍了如何实现一种易位加密算法,包括输入源文件、加密处理、解密处理和输出文件信息的步骤。文章详细展示了加密和解密函数的实现,以及密钥的排序处理。
摘要由CSDN通过智能技术生成

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define LINE  5   //每次处理的行数
void main()
{  
 void Inputsource(char *sourcefile);
 void Outputdoc(char *docfile);
 void encode(char *sourcefile,char *codefile,char *key);
 void decode(char *codefile,char *docfile,char *key);

 char *sourcefile="source_doc.dat";
 char *codefile="code.dat";
 char *docfile="doc.dat";
 char key[26];
 printf("Input the key word : /n");//输入密钥
 scanf("%s",key);
 getchar();
 Inputsource(sourcefile);//输入明文
 encode(sourcefile,codefile,key);//加密处理
 decode(codefile,docfile,key);//解密处理
 Outputdoc(sourcefile);//输出文件信息
 Outputdoc(codefile);
 Outputdoc(docfile);
 
}
void Inputsource(char *sourcefile)
{
 FILE *fpw_source;
 char ch;
 if((fpw_source=fopen(sourcefile,"w"))==NULL)
 {
  printf("Open source file Failure!!/n");
  exit(0);
 }
 printf("/nIn put your source doc ,and '!' for end :/n");
 while((ch=getchar())!='!')
 {
  fputc(ch,fpw_source);
 }
 fclose(fpw_source);
}
void Outputdoc(char *docfile)
{
 FILE *fpr_doc;
 char ch;
 if((fpr_doc=fopen(docfile,"r"))==NULL)
 {
  printf("Open docfile file Failure!!/n");
  exit(0);
 }
 printf("/nThe text of %s is :/n",docfile);
 while((ch=fgetc(fpr_do

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值