| 
				 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个字符作为密钥, word16是16位的  
//每个字符占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 
} 			
				 |