使用XOR门编码解码 [英] Encoding decoding using XOR gate

查看:168
本文介绍了使用XOR门编码解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
i需要为此创建个人编码方法



例如我有字符串参数A =P @ ssw0rd和B = 0xffa1

C = A XOR B

C是我的结果

很清楚

但在解码时

我必须用什么算子从C和B得到A ????

A = C(什么算子)B ??????



我的尝试:



字符串A =P @ ssw0rd; 
string B = 0xffa1;
C = A XOR B

解决方案

同一个!

 XOR B == C 
C XOR B == A



但是TBH XOR不是一个很好的加密算法,它太容易了打破 - 你不应该加密密码!您应该隐藏密码,而不是加密密码:密码存储:如何操作它。 [ ^ ]


按位 XOR 操作是可逆的:



(a xor b)xor b = a 



因此,如果可能已经完成,你可以撤销 XOR 'ecryption'只需 XOR 再次使用相同的密钥。


< blockquote class =quote>

引用:

但在解码时

我必须使用哪个运算符从C和B中获取A ???? / blockquote>

相同

第二个xor取消第一个。

所以当你有 C = A xor B ,您还将 A = C xor B B = A xor C 具有相同的A,B,C值。


hi i need to create method for personal encoding like this

for example i have string parameter A = "P@ssw0rd" and B = 0xffa1
C = A XOR B
C is my result
it's clear
but in decoding
what operator i have to use to get A from C and B????
A = C (what operator) B ??????

What I have tried:

string A = "P@ssw0rd";
string B = 0xffa1;
C = A XOR B

解决方案

The same one!

A XOR B == C
C XOR B == A


But TBH XOR is not an good encryption algorithm, it's far, far too easy to break - and you shouldn't be encrypting passwords anyway! You should Hash your passwords, not encrypt them: Password Storage: How to do it.[^]


Bitwise the XOR operation is reversible:

(a xor b) xor b = a


hence, if probably done, you can reverse the XOR 'ecryption' simply XORing again with the same key.


Quote:

but in decoding
what operator i have to use to get A from C and B????


Same
A second xor cancel the first one.
So when you have C=A xor B, you will also have A=C xor B and B=A xor C with same values for A,B,C.


这篇关于使用XOR门编码解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆