你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:杂志经典 / 计算机安全与维护
IDEA对称密码算法剖析(十二)
 

// 对文件明文加密函数,  in为明文流,out是辅助文件流,key为加密密钥(816)

void cipher_file(FILE *in,FILE *out,word16 *key)

{

   word16 input[4],output[4];

   IDEAkey Z;  //IDEAkey word16型的数组,52个元素

   int x,y;

   int count=0;

   long length;

   int temp;

 

   en_key_idea(key,Z);  // 生成52个子密钥

   end_of_file=0;

 

   length=filelength(fileno(in));  // 取得明文文件长度

   fwrite(&length,sizeof(long),1,out); // 写入文件长度(4个字节,32)out文件流

 

   while (!end_of_file)  //文件没有结束

   {

      x=0;

                   /*    核心代码    */

      while (x<4)  //读出64位明文,4次读出

      {

     input[x]=((word16)(read_char_from_file(in)<<8)); //一次读出8位明文 ,并左移8位 成为16位子分组的高8

     if (!end_of_file)

     {

        temp=read_char_from_file(in);  // 读出8位明文

 

        if (temp<0) temp+=256; 

        input[x]=input[x]|temp;  //  子分组的低8

        x++;

     }

     if (end_of_file)  //最后一次如果明文不足64, 0

     {

        while (x<4) input[x++]=0;

        break;

     }
  推荐精品文章

·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录
·2023年10月目录
·2023年9月目录 
·2023年8月目录 
·2023年7月目录
·2023年6月目录 
·2023年5月目录
·2023年4月目录 
·2023年3月目录 
·2023年2月目录 
·2023年1月目录 

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089