【发布时间】:2012-04-24 17:52:51
【问题描述】:
我一直在用这个工具做一些测试:http://crypto.hurlant.com/demo/CryptoDemo.swf 并一直在尝试匹配从 Mirc + blowfish 获得的河豚结果(来自过去的 fish.secure.us v1.30)。我这辈子都找不到它使用的模式......没有匹配的东西..有谁知道它使用什么模式??
【问题讨论】:
标签: actionscript-3 irc blowfish
我一直在用这个工具做一些测试:http://crypto.hurlant.com/demo/CryptoDemo.swf 并一直在尝试匹配从 Mirc + blowfish 获得的河豚结果(来自过去的 fish.secure.us v1.30)。我这辈子都找不到它使用的模式......没有匹配的东西..有谁知道它使用什么模式??
【问题讨论】:
标签: actionscript-3 irc blowfish
IRC 的 Blowfish 插件似乎使用 MODE_ECB(电子密码本),这可能是河豚算法中最不安全的。
为了加密,他们将明文分成 8 字节的块(Blowfish ECB 块大小)。然后他们分别加密每个 8 字节块,并获取每个加密块的输出,并将其分块为 (2) 个 4 字节长,并对每个长进行 base64 编码,将它们填充为 6 个 base64 字符的长度。
对于解密,这个过程是相反的,但因为它有点令人困惑,我也会描述一下。取 12 个密文字节,将每个 6 字节表示解码为 long ('>L'),这样您现在就有 8 个字节,然后将其传递给河豚解密算法。
import struct, string
from Crypto.Cipher import Blowfish
def blow(key, plaintext):
if not isinstance(plaintext, str):
raise TypeError('Plaintext must be str')
else:
if len(plaintext) % 8 != 0:
plaintext += "\0" * (8-(len(plaintext)%8))
cipher = Blowfish.new(key, Blowfish.MODE_ECB)
ciphertext = ''
charset = list('./' + string.digits + string.ascii_lowercase + string.ascii_uppercase)
for j in range(0,len(plaintext),8):
block = cipher.encrypt(plaintext[j:j+8])
(low, high) = struct.unpack('>LL', block)
while high:
ciphertext += charset[high%64]
high //= 64
if len(ciphertext) % 6 != 0:
ciphertext += charset[0] * (6-len(ciphertext)%6)
while low:
ciphertext += charset[low%64]
low //= 64
if len(ciphertext) % 6 != 0:
ciphertext += charset[0] * (6-len(ciphertext)%6)
assert len(ciphertext) % 12 == 0
return ciphertext
def unblow(key, ciphertext):
if not isinstance(ciphertext, str):
raise TypeError('Ciphertext must be str')
else:
assert len(ciphertext) % 12 == 0
cipher = Blowfish.new(key, Blowfish.MODE_ECB)
plaintext = bytearray()
charset = list('./' + string.digits + string.ascii_lowercase + string.ascii_uppercase)
for j in range(0,len(ciphertext),12):
high = 0
for k in range(6):
high |= charset.index(ciphertext[j+k]) << (k*6)
low = 0
for k in range(6):
low |= charset.index(ciphertext[j+k+6]) << (k*6)
plaintext += cipher.decrypt(struct.pack('>LL', low, high))
return plaintext.decode('utf8').rstrip("\0")
【讨论】:
它只是使用 ECB 模式,但是 base64 编码是以一种奇怪的方式完成的——每个 32 位密文块被独立编码成 6 个 base64 字符。
【讨论】:
IRC 不支持任何加密模式,所有内容都以纯文本形式传输,除非您使用 SSL。 Blowfish 是一种加密算法,它将翻译您的消息(在 mIRC 上)或您正在使用的任何客户端。
没有河豚的消息将被发送到服务器:
PRIVMSG #Channel :YourMessage
带有河豚的消息将被发送到服务器:
PRIVMSG #Channel :w8e09w8e09q8eqiwoqweqweqweqwueqwehwqheqywgBlowFishEncryption
【讨论】: