1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > C语言:用异或^实现数据加密

C语言:用异或^实现数据加密

时间:2023-02-11 09:42:33

相关推荐

C语言:用异或^实现数据加密

将需要加密的内容看做A,密钥看做B,A ^ B=加密后的内容C。

而解密时只需要将C ^ 密钥B=原内容A。如果没有密钥,就不能解密!

实例:

[html]

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#defineKEY0x86

intmain()

{

charp_data[16]={"HelloWorld!"};

charEncrypt[16]={0},Decode[16]={0};

inti;

for(i=0;i<strlen(p_data);i++)

{

Encrypt[i]=p_data[i]^KEY;

}

for(i=0;i<strlen(Encrypt);i++)

{

Decode[i]=Encrypt[i]^KEY;

}

printf("Initialdate:%s\n",p_data);

printf("Encryptdate:%s\n",Encrypt);

printf("Decodedate:%s\n",Decode);

return0;

}

运行结果:

[html]

Initialdate:HelloWorld!

Encryptdate:毋觋棣验絷猝

Decodedate:HelloWorld!

加密解密还支持多重加密,但是要记得加密的次数,解密时运用相同密钥做解密操作相同次数即可。

不仅如此,加密解密还支持多重不同密钥加密,只要你记得加密使用密钥!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。