views:

131

answers:

4

I know as a programmer that is rare for someone to do, but I actually need it and can not at all so someone needs to convert this small function cryptography python for delphi

function: ` from Crypto.Cipher import Blowfish

class Blowfish(object):
cipher = None

def __init__(self, key, mode = Blowfish.MODE_ECB):   
    self.cipher = Blowfish.new(key, mode)   

def encrypt(self, texto):   
    encriptar = self.cipher.encrypt(texto)   
    return encriptar `

one example key = 123key text = hi man result = ìûÕ]–•¢

I peopl much times because I tried to do in Delphi and always shows me different results then do better and ask for someone who understands python / delphi

thank so much!

A: 

If you just want to implement Blowfish algorithm in Delphi, try DCPcrypt.

Keeper
i tried DCPcrypt but evertime result diferences correctly is key = 123key text = hi man result = ìûÕ]–•¢but in DCP_crypt is key = 123key text = hi man result = kKPLZV=
Mili Coc
DCPCrypt returns the result in base64 encoding. The hex representation of the result is: 90A3CB6550. Don't try to use the result as a string: it's not and you're not going to get anything interesting out of it.
Stephane
how i can then ?, u have a example for me ?
Mili Coc
i tryied it var sTmp,IV,Key : String; begin Key := PadWithZeros('123key',32); IV := PadWithZeros('',16); DCP_blowfish1.Init(Key[1],192,@IV[1]); sTmp := PadWithZeros(Edit1.Text,16); DCP_blowfish1.EncryptECB(sTmp[1],sTmp[1]); Edit2.text := base64encode(stmp); memo1.lines.Add( 'Blowfish: '+stmp); memo1.lines.Add('BASE64encode: '+base64encode(stmp)); DCP_blowfish1.Burn; result of "hi man" is ¸ú"»Ì/Îb but in python and MMF is ìûÕ]–•¢ DAMN!! =/
Mili Coc
A: 

@Mili, you can't translate this code to delphi because does not exist a RTL library (or function) in delphi with blowfish support, dou you need use a third party component for this. i recommend you the Delphi Encryption Compedium Part I v.5.2. you can try out this link for more components.

RRUZ
same problem.. is result diferences =/
Mili Coc
@Mili, try using these test vectors to see wich implementation is wrong http://www.schneier.com/code/vectors.txt
RRUZ
idk.. i only can in multimedia fusion (DecryptString('BLOWFISH object'),'key','text') and python but in delphi i not search a correctly function
Mili Coc
i tryied it var sTmp,IV,Key : String;begin Key := PadWithZeros('123key',32); IV := PadWithZeros('',16); DCP_blowfish1.Init(Key[1],192,@IV[1]); sTmp := PadWithZeros(Edit1.Text,16); DCP_blowfish1.EncryptECB(sTmp[1],sTmp[1]); Edit2.text := base64encode(stmp); memo1.lines.Add( 'Blowfish: '+stmp); memo1.lines.Add('BASE64encode: '+base64encode(stmp)); DCP_blowfish1.Burn; result of "hi man" is ¸ú"»Ì/Îb but in python and MMF is ìûÕ]–•¢ DAMN!! =/
Mili Coc
+1  A: 

For the comment on DCPcrypt, maybe your python library results the raw encrypted bytes, and the result of DCPcrypt (or other delphi library like Turbo Lockbox) gives you the result encoded in something like UU64 o MIME (this is done to easily transfer o store the result)

Daniel Luyo
like http://www.tools4noobs.com/online_tools/encrypt/ same criptor but show results diferences :S.. in python have other function "padData" decrypting
Mili Coc
A: 

You can also try TurboPower LockBox 3.1.0 at http://lockbox.seanbdurkin.id.au/ . This library also implements Blowfish.

Sean B. Durkin