使用异或加密数据 2013-02-09 22:24 1043人阅读 评论(0) 收藏
(1)使用异或可简单加密数据,解密时使用加密后的数据与密钥重做一次异或运算即可。
(2)由于某些操作系统不能正确处理非打印字符,因此,对于此类字符可采取原有不做加密。
#include <stdio.h>
#include <ctype.h>
#define KEY 'z'
int main(void){
char orig_char, new_char;
orig_char=getchar();
while(orig_char!=EOF){
new_char=orig_char^KEY;
if(isprint(orig_char)&&isprint(new_char)){
putchar(new_char);
}else{
putchar(orig_char);
}
orig_char=getchar();
}
return 0;
}
运行程序时:
加密:xor <orig_file >new_file
解密:xor <new_file >orig_file
版权声明:本文为博主原创文章,未经博主允许不得转载。
欢迎转载,请注明来自:
www.lujinhong.com
www.cnblogs.com/lujinhong2

浙公网安备 33010602011771号