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

/*IDEA Algorithm functions */

void en_key_idea(word16 userkey[8],IDEAkey Z);

void de_key_idea(IDEAkey Z, IDEAkey DK);

void cipher_idea(word16 in[4],word16 out[4],IDEAkey Z);

uint16 inv(uint16 x);

uint16 mul(uint16 a,uint16 b);

 

/*file handling functions*/

char read_char_from_file(FILE *fp);

word16 read_word16_from_file(FILE *fp);

void write_char_to_file(char data,FILE *fp);

void write_word16_to_file(word16 data,FILE *fp);

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

void decipher_file(FILE *in,FILE *out,word16 *key);

void swap_files_and_clean_up(char *file);

 

void GetChoice(int &choice , char szFileName[100] ,char szKey[50]);

 

#endif

3.3  cpp文件部分

/*idea.cpp*/

#include "idea.h"

/*实现把加密密钥转换为解密密钥, 加密密钥与解密密钥的模216+1乘 等于 1 MOD(216+1)*/

static uint16 inv(uint16 x)

{

   uint16 t0,t1;

   uint16 q,y;

   if (x<=1)

      return x;

   t1=(uint16)(0x10001l/x); 

   y=(uint16)(0x10001l%x);

   if (y==1)

    return low16(1-t1);

   t0=1;

   do

   {

      q=x/y;

      x=x%y;

      t0+=q*t1;
  推荐精品文章

·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