本文介绍了什么是XOR加密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说有人开始加密,并认为这可能是我想要的东西,所以我检查了XOR并没有任何意义.那么有人可以向我解释什么是XOR?

I have heard about people starting encryption and thought it may be something I would like, so I checked XOR and can't make any sense of it.So can someone explain to me what XOR is ?

推荐答案

XOR是逻辑运算,发音为 exclusive或.它可用于简单快速地对消息进行加密.您可以在此处查看此操作的真值表: http://mathworld.wolfram.com/XOR.html

XOR is a logical operation, pronounced exclusive or. It can be used to cipher messages simply and fast. You can see a truth table for this operation here: http://mathworld.wolfram.com/XOR.html

准伪代码实现(通过 http://www.evanfosmark.com/2008/06/xor-encryption-with-python/):

#!/usr/bin/env python

from itertools import izip, cycle

def xor_crypt_string(data, key):
    return ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key)))

my_data = "Hello. This is a secret message! How fun."
my_key= "firefly"

# Do the actual encryption
encrypted = xor_crypt_string(my_data, key=my_key)

print encrypted
print '---->'

# This will obtain the original data from the encrypted
original = xor_crypt_string(encrypted, key=my_key)

print original

输出:

.     BY2F
FRR
DF$IB
---->
Hello. This is a secret message! How fun.

这篇关于什么是XOR加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 15:27
查看更多