使用异或加密数据

mac2022-06-30  24

(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

转载于:https://www.cnblogs.com/jinhong-lu/archive/2013/02/09/4559564.html

最新回复(0)