私はこのツールでいくつかのテストを行ってきました: http://crypto.hurlant.com/demo/CryptoDemo.swf と Mirc + フグ (以前は fish.secure.us v1 であったものから) から得られたフグの結果と一致させようとしています。 .30)。私は一生、それが使用しているモードを見つけることができません...一致するものはありません..誰もそれが使用するモードを知っていますか??
3 に答える
IRC 用の Blowfish プラグインは MODE_ECB (電子コード ブック) を使用しているように見えますが、これはおそらく、blowfish アルゴリズムの中で最も安全性が低いものです。
暗号化のために、平文を 8 バイトのチャンク (Blowfish ECB ブロックサイズ) に分割します。次に、各 8 バイト ブロックを個別に暗号化し、暗号化された各ブロックの出力を取得し、それを (2) 4 バイト long にチャンクし、各 long を base64 エンコードして、6 base64 文字の長さにパディングします。
復号化の場合はこのプロセスが逆になりますが、少しややこしいのでそれについても説明します。12 バイトの暗号文を取得し、各 6 バイト表現を long ('>L') としてデコードすると、8 バイトになり、blowfish 復号化アルゴリズムに渡します。
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