当前位置:编程学习 > C/C++ >>

一个异或加密方案--C语言实现

核心代码:
 
 
char encrypt( char f , char c)  
{  
    return f^c;  
}  

 

 
 
 int OutEncrypt( char *FilePath, char *SecretWord )  
{  
    FILE *  fp ;  
    FILE * fp1;  
    char *p= FilePath , *s= SecretWord;  
    //char fn[128], *p = fn, ps[10], *s = ps;   //fn[128]存放加密文件路径,ps[10]存放密码  
    char ch;  
    char *tm = "C:\\temp.temp";   //存放临时文件  
  
    if(( fp = fopen(p,"rb") )== NULL || ( fp1 = fopen(tm,"wb") ) == NULL )  
    {  
        return 0;    //加密失败  
    }  
  
    ch = fgetc(fp);  
    while( !feof(fp) )  
    {  
        s = SecretWord;  
        while( *s != '\0' )  
        {  
            ch = encrypt( ch, *s++ );  
            fputc( ch, fp1 );  
            ch = fgetc(fp);  
        }  
    }  
    fclose( fp );  
    fclose( fp1);  
    remove(p);  
    rename(tm, p);  
  
    return 1;   //加密成功  
}  

 

 
 
补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,