C 一次pad中两个密文的异或信息给了我什么?
因此,我们被告知不要对一次性pad使用相同的密钥,因为如果攻击者知道这两个密文,他可以得到这两个明文的异或。例如:C 一次pad中两个密文的异或信息给了我什么?,c,cryptography,cryptanalysis,C,Cryptography,Cryptanalysis,因此,我们被告知不要对一次性pad使用相同的密钥,因为如果攻击者知道这两个密文,他可以得到这两个明文的异或。例如: Plain Text1: 0001011 Key : 1010110 Ciphertext : 1011101 Plain Text2: 0110011 Key : 1010110 Ciphertext : 1100101 XOR of ciphertexts 1011101 1100101 0111000 XOR of plaintexts (w
Plain Text1: 0001011
Key : 1010110
Ciphertext : 1011101
Plain Text2: 0110011
Key : 1010110
Ciphertext : 1100101
XOR of ciphertexts
1011101
1100101
0111000
XOR of plaintexts (which of course match)
0001011
0110011
0111000
但这些信息究竟给了攻击者什么好处呢?他能用这两个纯文本的异或做什么?我想会有很多其他答案,但你可以做以下事情-试着猜测一个已知单词在给定位置的文本中,并用这个单词异或该位置。如果该值看起来合理(从统计上看,它类似于您感兴趣的明文),那么您知道这两种明文的一部分 假设您有以下明文异或(或密文,对于问题中描述的情况相同,其中密文==明文异或OTP): 现在,您尝试匹配字典中的单词,并发现如果将此字符串与位置1处的“correct”异或,则会得到:
some ot
好的,那么你的明文很可能是:
correct.....
some ot.....
现在试着用xor对以“ot…”开头的单词进行xor,并找出“other”的单词(以及已知的开头):
所以你的明文是:
correct ho....
some other....
以此类推,您可以恢复两个完整的字符串。对于非英语单词的明文来说,这当然会更难,但仍然是可能的。而且您在任何时候都不需要知道OTP内容。两个明文的异或对攻击者非常有用。例如,空格字符(ascii 32)与字母字符异或时,只需更改大小写即可。因此,如果一个明文中有很多空格,您可以通过颠倒大小写来读取另一个明文。避免将字母用作一次传递(使用循环算术)。如果有人收到密码文本
GUTV
关于纯文本,除了它有4个字母长之外,人们什么都不知道。
可能是
炸弹、爱情或其他任何词语。你无法区分,而且两者的可能性都比另一个大
但若你们有两个纯文本使用同一个pad,这意味着一旦你们采用了一个解决方案,第二个就会自动定义
使用一些尝试和错误(或计算机与词汇),你可以显着减少到只有几个选项在最坏的情况下
所以你可以从完全安全的东西(真正的一次性垫子)变成容易破碎的东西
编辑
这是用python编写的小破解程序
你需要一个字档。我从
这个密码的作用它需要两个单词bomb
和love
,并使用pad/passwordhaha
对两者进行加密。然后,它找出所有可能的密码,这些密码将此cypertexts对解密为词汇表中的单词
import re
with open("big.txt","r") as f:
words = set(re.findall('[a-z]+', f.read().lower()))
def encrypt(word,password):
add_letters = lambda x,y:chr((ord(x)+ord(y)-2*ord('a'))%26 + ord('a'))
return "".join(add_letters(*i) for i in zip(word.lower(),password.lower()))
def decrypt(word,password):
sub_let = lambda x,y:chr((ord(x)-ord(y)+26)%26 + ord('a'))
return "".join(sub_let(*i) for i in zip(word.lower(),password.lower()))
def crack(a,b):
assert(len(a) == len(b))
w = (i for i in words if len(i) == len(a))
for i in w:
password = decrypt(a,i)
b_plain= decrypt(b,password)
if b_plain in words:
print(i,b_plain,password)
password = "haha"
a="bomb"
b="love"
a_cyper=encrypt(a,password)
b_cyper=encrypt(b,password)
print("cyper",a_cyper,b_cyper)
crack(a_cyper,b_cyper)
输出:
('cyper', 'iotb', 'soce')
('tomb', 'dove', 'paha')
('bath', 'lack', 'hoau')
('bomb', 'love', 'haha') <---
('vote', 'foch', 'naax')
('reid', 'berg', 'rkly')
('tank', 'dawn', 'pogr')
('felo', 'peur', 'dkin')
('hath', 'rack', 'boau')
('cork', 'moan', 'gacr')
('rath', 'back', 'roau')
('ruth', 'buck', 'ruau')
('bank', 'lawn', 'hogr')
('rake', 'bath', 'rojx')
('mike', 'with', 'wgjx')
('hero', 'rear', 'bkcn')
('comb', 'move', 'gaha')
('foch', 'polk', 'daru')
('foci', 'poll', 'dart')
('both', 'lock', 'haau')
('peri', 'zeal', 'tkct')
('maim', 'warp', 'wolp')
('limb', 'vive', 'xgha')
('cyper'、'iotb'、'soce')
(“坟墓”、“鸽子”、“帕哈”)
('bath'、'lack'、'hoau')
(‘bomb’、‘love’、‘haha’)不完全是两个密文的异或,但可以执行蛮力攻击,用当前猜测的密钥对第一个密文和第二个密文进行异或;如果他们匹配,答对了。我不是密码专家,但知道其中一个明文的攻击者难道不能恢复另一个明文吗?请注意,如果知道多个密文,密钥可以一次强制一个字母-此方法不涉及将密文异或在一起。@KerrekSB假设密文是由OTP xor明文生成的,然后,ciphertext1 xor ciphertext2==明文1 xor明文2。上面的例子就是这个值(消息的xor)。
import re
with open("big.txt","r") as f:
words = set(re.findall('[a-z]+', f.read().lower()))
def encrypt(word,password):
add_letters = lambda x,y:chr((ord(x)+ord(y)-2*ord('a'))%26 + ord('a'))
return "".join(add_letters(*i) for i in zip(word.lower(),password.lower()))
def decrypt(word,password):
sub_let = lambda x,y:chr((ord(x)-ord(y)+26)%26 + ord('a'))
return "".join(sub_let(*i) for i in zip(word.lower(),password.lower()))
def crack(a,b):
assert(len(a) == len(b))
w = (i for i in words if len(i) == len(a))
for i in w:
password = decrypt(a,i)
b_plain= decrypt(b,password)
if b_plain in words:
print(i,b_plain,password)
password = "haha"
a="bomb"
b="love"
a_cyper=encrypt(a,password)
b_cyper=encrypt(b,password)
print("cyper",a_cyper,b_cyper)
crack(a_cyper,b_cyper)
('cyper', 'iotb', 'soce')
('tomb', 'dove', 'paha')
('bath', 'lack', 'hoau')
('bomb', 'love', 'haha') <---
('vote', 'foch', 'naax')
('reid', 'berg', 'rkly')
('tank', 'dawn', 'pogr')
('felo', 'peur', 'dkin')
('hath', 'rack', 'boau')
('cork', 'moan', 'gacr')
('rath', 'back', 'roau')
('ruth', 'buck', 'ruau')
('bank', 'lawn', 'hogr')
('rake', 'bath', 'rojx')
('mike', 'with', 'wgjx')
('hero', 'rear', 'bkcn')
('comb', 'move', 'gaha')
('foch', 'polk', 'daru')
('foci', 'poll', 'dart')
('both', 'lock', 'haau')
('peri', 'zeal', 'tkct')
('maim', 'warp', 'wolp')
('limb', 'vive', 'xgha')