数据加密解密的原理也很简单,就是使用异或运算。请先看下面的代码:
#include <stdio.h>
#include <stdlib.h>
int main(){
char plaintext = 'a'; // 明文
char secretkey = '!'; // 密钥
char ciphertext = plaintext ^ secretkey; // 密文
char decodetext = ciphertext ^ secretkey; // 解密后的字符
char buffer[9];
printf(" char ASCII\n");
// itoa()用来将数字转换为字符串,可以设定转换时的进制(基数)
// 这里将字符对应的ascii码转换为二进制
printf(" plaintext %c %7s\n", plaintext, itoa(plaintext, buffer, 2));
printf(" secretkey %c %7s\n", secretkey, itoa(secretkey, buffer, 2));
printf("ciphe