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

if ((remove(file))!=0)  //删除原文件

      {

     printf("\nERROR removing old file <%s>\n",file);

     printf("encoded data remains in temporary file <%s>\n",tempfilename);

     exit(-1);

      }

   }

   else

   {   // 不覆盖文件, 则生成以原文件同名,. enc结尾的新文件

      strcpy(temp,file);

      file=strtok(temp,".");

      strcat(file,".enc");

   }

 

   if ((rename(tempfilename,file))!=0) //更改辅助文件名为原文件名, 因为原文件已被删除

   {

      printf("\nERROR renaming temporary file <%s>!!\n",tempfilename);

      printf("Data is safely processed and stored in that file.\n");

   }

 

}

#define KBYTES 1024

//格式化密钥

//注意:  这里用输入的前8个字符作为密钥, word1616位的

//每个字符占8, 这里把每个8位的字符转换成16位的word16 (短整型)作为密钥, 存放在key

void getuserkeyfromargv(word16 *key,char *arg)

{

   int x;

 

   for (x=0;x<strlen(arg) && x<8;x++)

   {

       if (x==0) key[x]=arg[x]<<8;      // 第一个密钥是第一个字符左移8位得到

       else key[x]=((arg[x]<<8)|(key[x-1]>>8));   /*第二个密钥起高8位是相应的字符, 8位是前一个字符*/

   }

 

   if (strlen(arg)>8) printf ("\nONLY first *8* characters of key used!!!\n");

 

   if (x<8) while (x<8) key[x++]=0;  //如果输入不足八个字符则剩下相应的密钥填0

}

  推荐精品文章

·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