Blowfish Encryption Componet
@sec: Simple to get a full 448 bits out of it consistantly. Oh, and I've checked the rest of the code stuff from the URL,sec. I was right in my previous statement that mine wasn't compatable due to my choice hash for the key. The hash is a SHA512 which is huge, and as a result we get key big enough for the whole 448 bits reguardless of what the password/key is some one enters.
I am using this code which is a very good work, nice piece of code.
However I have two questions :
- when I use the Blowfish_SetKey(ptrKey.s,lKey.l) procedure,
does Blowfish_SetKey("mykey", 5) means that I use a 5 x 8 = 40 bits key ?
If so I do a MD5 of the word to obtain a 32Bytes password, is the blowfish
key is 32 x 8 = 256 bits ?
- when do I have to call Blowfish_Clear(), at the end of the program when
it finish ?
Thanks in advance.
EDIT :
just to share, I have done those two simple procedure, easier to use like this :
and to use it :
However I have two questions :
- when I use the Blowfish_SetKey(ptrKey.s,lKey.l) procedure,
does Blowfish_SetKey("mykey", 5) means that I use a 5 x 8 = 40 bits key ?
If so I do a MD5 of the word to obtain a 32Bytes password, is the blowfish
key is 32 x 8 = 256 bits ?
- when do I have to call Blowfish_Clear(), at the end of the program when
it finish ?
Thanks in advance.
EDIT :
just to share, I have done those two simple procedure, easier to use like this :
Code: Select all
Procedure Encrypt(*Buffer)
*Crypt = AllocateMemory(1000)
For a = 0 To Len(PeekS(*Buffer)) Step 8
Blowfish_Encrypt(*Crypt + a, *Buffer + a) ;Blowfish_Encrypt(wohin Buffer, was soll encryptet werden)
Next a
ProcedureReturn *Crypt
EndProcedure
Procedure Decrypt(*Buffer)
*Decrypt = AllocateMemory(1000)
For a = 0 To Len(PeekS(*Buffer)) Step 8 ;8 byte Verschlüsselung
Blowfish_Decrypt(*Decrypt + a, *Buffer + a) ;Blowfish_Decrypt(wohin Buffer, was soll decryptet werden)
Next a
ProcedureReturn *Decrypt
EndProcedure
Code: Select all
text.s = "toto"
*Buffer = GlobalAlloc_(#GMEM_FIXED | #GMEM_ZEROINIT, 1000)
PokeS(*Buffer, text)
result.s = PeekS(Encrypt(*Buffer))
- Registered PB user -
Using PB 4.00
Using PB 4.00
-
sec
- Enthusiast

- Posts: 792
- Joined: Sat Aug 09, 2003 3:13 am
- Location: 90-61-92 // EU or ASIA
- Contact:
Right.does Blowfish_SetKey("mykey", 5) means that I use a 5 x 8 = 40 bits key ?
If so I do a MD5 of the word to obtain a 32Bytes password, is the blowfish
key is 32 x 8 = 256 bits ?
but with MD5 ..from manual:
Result$ is a hex string, I suppose.Result$ = MD5Fingerprint(Buffer, Length)
Description
Returns a 32 characters long MD5 (Message Digest 5) hash code.
..
'The algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input.
You could find some algo that produces a larger hash (as SHA2(SHA512))
Edit: @Num3 i forgot update
Code: Select all
#lengthkey = 7
Dim Key.b(#lengthkey -1)
Key(0) = Asc("T"):Key(1) = Asc("E"):Key(2) = Asc("S"):Key(3) = Asc("T")
Key(4) = Asc("K"):Key(5) = Asc("E"):Key(6) = Asc("Y"):
;Key(4) = 00:Key(5) = 00:Key(6) = 11 ; value 0..255 allow
BlowFishInit(@Key(),7)
ptrin.s="1234567812345678"
ptrout.s=Space(16)
BlowFishEncrypt(@ptrout, @ptrin)
BlowFishEncrypt(@ptrout+8, @ptrin+8)
Debug ptrout
BlowFishDecrypt(@ptrin, @ptrout)
BlowFishDecrypt(@ptrin+8, @ptrout+8)
Debug ptrin
BlowFishFinal() ; Clear session key32 characters... 128 bits ?
If in the first example, a 5 characters long password is 5 x 8 = 40 bits,
someone has to explain me why a MD5 fingerprint which is always
32 characters long is not a 32 x 8 = 256 bits password ?
I am not good at maths, that's a fact, but anyway this two examples seems opposite.
About SHA, yes it would interest me, I have just use built in PB command, but SHA-1 or SHA-256 would be definitly better for making the password.
If in the first example, a 5 characters long password is 5 x 8 = 40 bits,
someone has to explain me why a MD5 fingerprint which is always
32 characters long is not a 32 x 8 = 256 bits password ?
I am not good at maths, that's a fact, but anyway this two examples seems opposite.
About SHA, yes it would interest me, I have just use built in PB command, but SHA-1 or SHA-256 would be definitly better for making the password.
- Registered PB user -
Using PB 4.00
Using PB 4.00
-
sec
- Enthusiast

- Posts: 792
- Joined: Sat Aug 09, 2003 3:13 am
- Location: 90-61-92 // EU or ASIA
- Contact:
MD5 aglo produces 128 bit _16 bytes_ and you had know a byte is range from 0..255 so for reabable or printable all chars, each byte is encoded using two hex digits. (and 16xtwohexdigitsforeachbyte = 32)
MD5Fingerprint would have a option same as:
Result$ = MD5Fingerprint(Buffer, Length [,*Raw bytes])
MD5Fingerprint would have a option same as:
Result$ = MD5Fingerprint(Buffer, Length [,*Raw bytes])
I have a problem that I can't solve since yesteday, I have spent many huors on it today to no avail
I have taken the original source code from this thread, I added the two procedures (crypt / encrypt) that I want to use in my programs.
THE IMPORTANT PART
What is the difference between my two procedures and the original source code ?
Please note that I've written in "Text$" a known set of characters which makes my decrypt procedure to not completly decrypt it.
For most of the sentences, my two procs will work, but sometimes not.
This example is one case where the original sourec code decrypt it right
while mine is failing.
Wth is the difference ?
(you can copy/past the whole thing and see the Debugs by yourself)
EDIT :
in the above code, replace the middle with :
and sudently the original code does not work anymore too.
Unfortunaly, in real program use, the "FreeMemory" means that we do not
encrypted the text, we just start after, with the encrypted form, to decrypt.
Is the code buggy and not reliable or do I miss something ?
I have taken the original source code from this thread, I added the two procedures (crypt / encrypt) that I want to use in my programs.
Code: Select all
; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=4972&highlight=
; Author: Dristar
; Date: 03. July 2004
;***************************************************
;* Coded by Dristar 02.07.2004 *
;* für PureBasic *
;***************************************************
*speicher = AllocateMemory(4500)
aPBox =*speicher ;SP = SpeicherPointer ermitteln
aSBox1 =*speicher + (18 * 4)
aSBox2 =aSBox1 + (256 * 4)
aSBox3 =aSBox2 + (256 * 4)
aSBox4 =aSBox3 + (256 * 4)
aInternalKey =aSBox4 + (256 * 4)
Procedure Blowfish_Encrypt(ptrOut.l,ptrIn.l)
MOV Edi, ptrIn
!MOV Eax, dword [Edi+0]
!MOV Edx, dword [Edi+4]
!XOR Ebx, Ebx
!XOR Ecx, Ecx
!XOR Edi, Edi
encrypt1:
!MOV Ebp ,[ds:v_aPBox] ;aPBox SP
!XOR Eax, [ds:Ebp+4*Edi]
!ROL Eax, 16
!MOV cl, al
!MOV bl, ah
!MOV Ebp ,[ds:v_aSBox2] ;aSBox2 SP
!MOV Esi, dword [ds:Ebp+4*Ecx]
!ROL Eax, 16
!MOV Ebp ,[ds:v_aSBox1] ;aSBox1 SP
!ADD Esi, dword [ds:Ebp+4*Ebx]
!MOV cl, ah
!MOV bl, al
!MOV Ebp ,[ds:v_aSBox3] ;aSBox3 SP
!XOR Esi, dword [ds:Ebp+4*Ecx]
!MOV Ebp ,[ds:v_aSBox4] ;aSBox4 SP
!ADD Esi, dword [ds:Ebp+4*Ebx]
!XOR Edx, Esi
!INC Edi
!XCHG Eax, Edx
!CMP Edi, 16
!JNZ l_encrypt1
MOV Esi, ptrOut
!MOV Ebp ,[ds:v_aPBox] ;aPBox SP
!XOR Eax, [ds:Ebp+16*4]
!XOR Edx, [ds:Ebp+17*4]
!MOV dword [Esi+4], Eax
!MOV dword [Esi+0], Edx
EndProcedure
Procedure Blowfish_SetKey(ptrKey.s,lKey.l)
*zeax = 0
*zedi = 0
!MOV Ecx, 256*4+ 18 ;1042 Zeichen Kopieren
!MOV Esi, l_pbox ;was Kopieren ? (Tabelle)
!MOV Edi, [ds:v_aPBox] ;wohin ? (*speicher)
!CLD ;flag löschen fals vorhanden
!REP movsd ;Komplette Tabellen in den Speicher Kopieren
MOV Ecx, lKey ;Password Länge vom Stack
!MOV Edx, 18*4
!TEST Ecx, Ecx ;Password vorhanden ?
!JZ l_nokey
!CMP Ecx, 56 ;maxkeysize (448bit)
!JB l_setkey1
!MOV Ecx, 56
setkey1:
!MOV Edx, 18*4
MOV Esi, ptrKey ;Password String vom Stack
!SUB Edx, Ecx ;rest = 56 - Password länge
!REP movsb ;Password String in speicher Kopieren
!MOV Ecx, Edx ;wieviel ? rest auf ECX legen
!MOV Esi, [ds:v_aInternalKey] ;wohin ? Speicher Pointer in ESI
!REP movsb ;Password String wiederhollen bis es 56 zeichen sind
!MOV Ecx, 18*4
setkey2:
!MOV Ebp ,[ds:v_aInternalKey] ;Speicher Pointer auslessen
!MOV Eax, dword [ds:Ebp+ Ecx -4] ;Password String lesen
!BSWAP Eax
!MOV Ebp ,[ds:v_aPBox] ;aPBox Speicher Pointer auslessen
!XOR dword [ds:Ebp+ Ecx -4], Eax ;Tabelle mit Password String xor'en
!SUB Ecx, 4
!JNZ l_setkey2 ;ende der Tabelle erreicht ?
!XOR Eax, Eax ;erzeuge zero-string
!MOV Edi, [ds:v_aPBox] ;aPBox Speicher Pointer auslessen
!MOV Ebp ,[ds:v_aInternalKey] ;aInternalKey Speicher Pointer auslessen
!MOV dword [ds:Ebp], Eax
!MOV dword [ds:Ebp+4], Eax
!MOV Ecx, 9 ;aPBox len/2 in dwords
!PUSH Ebp ;aInternalKey Pointer sichern
!POP Eax ;auf EAX legen
x_loop:
MOV *zeax ,Eax
y_loop:
MOV *zedi ,Edi
Blowfish_Encrypt(*zedi,*zeax)
!MOV Eax, Edi
!ADD Edi, 8
!DEC Ecx
!JNZ l_x_loop
!MOV Ecx, 4*256/2 ;aSBox len/2 in dwords
setkey3:
MOV *zeax ,Eax
MOV *zedi ,Edi
Blowfish_Encrypt(*zedi,*zeax)
!MOV Eax, Edi
!ADD Edi, 8
!DEC Ecx
!JNZ l_setkey3
nokey:
EndProcedure
Procedure Blowfish_Decrypt(ptrOut.l,ptrIn.l)
MOV Edi, ptrIn
!MOV Eax, dword [Edi+0]
!MOV Edx, dword [Edi+4]
!XOR Ebx, Ebx
!XOR Ecx, Ecx
!MOV Edi, 16
decrypt1:
!MOV Ebp ,[ds:v_aPBox] ;aPBox SPointer
!XOR Eax, [ds:Ebp+4*Edi+4]
!ROL Eax, 16
!MOV cl, al
!MOV bl, ah
!MOV Ebp ,[ds:v_aSBox2] ;aSBox2 SP
!MOV Esi, dword [ds:Ebp+4*Ecx]
!ROL Eax, 16
!MOV Ebp ,[ds:v_aSBox1] ;aSBox1 SP
!ADD Esi, dword [ds:Ebp+4*Ebx]
!MOV cl, ah
!MOV bl, al
!MOV Ebp ,[ds:v_aSBox3] ;aSBox3 SP
!XOR Esi, dword [ds:Ebp+4*Ecx]
!MOV Ebp ,[ds:v_aSBox4] ;aSBox4 SP
!ADD Esi, dword [ds:Ebp+4*Ebx]
!XOR Edx, Esi
!DEC Edi
!XCHG Eax, Edx
!JNZ l_decrypt1
MOV Esi, ptrOut
!MOV Ebp ,[ds:v_aPBox] ;aPBox SPointer auslessen
!XOR Eax, [ds:Ebp+ 1*4] ;L = L ^ Pbox[1]
!XOR Edx, [ds:Ebp+ 0*4] ;R = R ^ Pbox[0]
!MOV dword [Esi+4], Eax
!MOV dword [Esi+0], Edx
EndProcedure
Procedure Blowfish_Clear()
!PUSH Eax
!PUSH Ecx
!PUSH Edi
!MOV Ecx, 256*4 + 18*2
!MOV Edi, [ds:v_aPBox] ;aPBox SP
!XOR Eax, Eax
!CLD
!REP stosd
!POP Edi
!POP Ecx
!POP Eax
EndProcedure
Code: Select all
#CRYPT_BUFFER_SIZE = 4096
Text$="maximum t limité dans les 500 caractères" : Debug Text$
temp.s = "toto" : temp = MD5Fingerprint(temp, Len(temp)) : temp + "aaaaaaaaaaaaaaaaaaaaaaaa" : Blowfish_SetKey(temp,56)
Debug "Len(Text$) = " + Str(Len(Text$) ) ; = 40
Procedure.s Encrypt(*Buffer)
*Crypt = AllocateMemory(#CRYPT_BUFFER_SIZE)
For a=0 To 40 Step 8
Blowfish_Encrypt(*Crypt+a,*Buffer+a) ;Blowfish_Encrypt(wohin Buffer, was soll encryptet werden)
Next a
ProcedureReturn PeekS(*Crypt)
EndProcedure
Procedure.s Decrypt(*Buffer)
*Decrypt = AllocateMemory(#CRYPT_BUFFER_SIZE)
For a=0 To 40 Step 8 ;8 byte Verschlüsselung
Blowfish_Decrypt(*Decrypt + a, *Buffer + a) ;Blowfish_Decrypt(wohin Buffer, was soll decryptet werden)
Next a
ProcedureReturn PeekS(*Decrypt)
EndProcedure
; ###### FAILS #######
*Buffer = AllocateMemory(4096)
PokeS(*Buffer, Text$)
enc.s = Encrypt(*Buffer) ; OK
Debug "my proc : crypt = " + enc
Debug "my proc : decrypt = " + Decrypt(@enc) ; NOT OK
Debug " "
; ###### WORKS #######
*mem0=AllocateMemory(4096)
*mem1=AllocateMemory(4096)
PokeS(*mem0, Text$)
For a=0 To Len(Text$) Step 8
Blowfish_Encrypt(*mem1+a,*mem0+a) ;Blowfish_Encrypt(wohin Buffer, was soll encryptet werden)
Next a
Debug PeekS(*mem1)
FreeMemory(*mem0)
*mem0=AllocateMemory(4096)
For a=0 To Len(Text$) Step 8 ;8 byte Verschlüsselung
Blowfish_Decrypt(*mem0+a,*mem1+a) ;Blowfish_Decrypt(wohin Buffer, was soll decryptet werden)
Next a
Debug PeekS(*mem0)
Blowfish_Clear()
What is the difference between my two procedures and the original source code ?
Please note that I've written in "Text$" a known set of characters which makes my decrypt procedure to not completly decrypt it.
For most of the sentences, my two procs will work, but sometimes not.
This example is one case where the original sourec code decrypt it right
while mine is failing.
Wth is the difference ?
(you can copy/past the whole thing and see the Debugs by yourself)
Code: Select all
End
PBox:
!DD 0243f6a88h, 085a308d3h, 013198a2eh, 003707344h, 0a4093822h, 0299f31d0h, 0082efa98h, 0ec4e6c89h, 0452821e6h, 038d01377h, 0be5466cfh, 034e90c6ch
!DD 0c0ac29b7h, 0c97c50ddh, 03f84d5b5h, 0b5470917h, 09216d5d9h, 08979fb1bh
SBox1:
!DD 0d1310ba6h, 098dfb5ach, 02ffd72dbh, 0d01adfb7h, 0b8e1afedh, 06a267e96h, 0ba7c9045h, 0f12c7f99h, 024a19947h, 0b3916cf7h, 00801f2e2h, 0858efc16h
!DD 0636920d8h, 071574e69h, 0a458fea3h, 0f4933d7eh, 00d95748fh, 0728eb658h, 0718bcd58h, 082154aeeh, 07b54a41dh, 0c25a59b5h, 09c30d539h, 02af26013h
!DD 0c5d1b023h, 0286085f0h, 0ca417918h, 0b8db38efh, 08e79dcb0h, 0603a180eh, 06c9e0e8bh, 0b01e8a3eh, 0d71577c1h, 0bd314b27h, 078af2fdah, 055605c60h
!DD 0e65525f3h, 0aa55ab94h, 057489862h, 063e81440h, 055ca396ah, 02aab10b6h, 0b4cc5c34h, 01141e8ceh, 0a15486afh, 07c72e993h, 0b3ee1411h, 0636fbc2ah
!DD 02ba9c55dh, 0741831f6h, 0ce5c3e16h, 09b87931eh, 0afd6ba33h, 06c24cf5ch, 07a325381h, 028958677h, 03b8f4898h, 06b4bb9afh, 0c4bfe81bh, 066282193h
!DD 061d809cch, 0fb21a991h, 0487cac60h, 05dec8032h, 0ef845d5dh, 0e98575b1h, 0dc262302h, 0eb651b88h, 023893e81h, 0d396acc5h, 00f6d6ff3h, 083f44239h
!DD 02e0b4482h, 0a4842004h, 069c8f04ah, 09e1f9b5eh, 021c66842h, 0f6e96c9ah, 0670c9c61h, 0abd388f0h, 06a51a0d2h, 0d8542f68h, 0960fa728h, 0ab5133a3h
!DD 06eef0b6ch, 0137a3be4h, 0ba3bf050h, 07efb2a98h, 0a1f1651dh, 039af0176h, 066ca593eh, 082430e88h, 08cee8619h, 0456f9fb4h, 07d84a5c3h, 03b8b5ebeh
!DD 0e06f75d8h, 085c12073h, 0401a449fh, 056c16aa6h, 04ed3aa62h, 0363f7706h, 01bfedf72h, 0429b023dh, 037d0d724h, 0d00a1248h, 0db0fead3h, 049f1c09bh
!DD 0075372c9h, 080991b7bh, 025d479d8h, 0f6e8def7h, 0e3fe501ah, 0b6794c3bh, 0976ce0bdh, 004c006bah, 0c1a94fb6h, 0409f60c4h, 05e5c9ec2h, 0196a2463h
!DD 068fb6fafh, 03e6c53b5h, 01339b2ebh, 03b52ec6fh, 06dfc511fh, 09b30952ch, 0cc814544h, 0af5ebd09h, 0bee3d004h, 0de334afdh, 0660f2807h, 0192e4bb3h
!DD 0c0cba857h, 045c8740fh, 0d20b5f39h, 0b9d3fbdbh, 05579c0bdh, 01a60320ah, 0d6a100c6h, 0402c7279h, 0679f25feh, 0fb1fa3cch, 08ea5e9f8h, 0db3222f8h
!DD 03c7516dfh, 0fd616b15h, 02f501ec8h, 0ad0552abh, 0323db5fah, 0fd238760h, 053317b48h, 03e00df82h, 09e5c57bbh, 0ca6f8ca0h, 01a87562eh, 0df1769dbh
!DD 0d542a8f6h, 0287effc3h, 0ac6732c6h, 08c4f5573h, 0695b27b0h, 0bbca58c8h, 0e1ffa35dh, 0b8f011a0h, 010fa3d98h, 0fd2183b8h, 04afcb56ch, 02dd1d35bh
!DD 09a53e479h, 0b6f84565h, 0d28e49bch, 04bfb9790h, 0e1ddf2dah, 0a4cb7e33h, 062fb1341h, 0cee4c6e8h, 0ef20cadah, 036774c01h, 0d07e9efeh, 02bf11fb4h
!DD 095dbda4dh, 0ae909198h, 0eaad8e71h, 06b93d5a0h, 0d08ed1d0h, 0afc725e0h, 08e3c5b2fh, 08e7594b7h, 08ff6e2fbh, 0f2122b64h, 08888b812h, 0900df01ch
!DD 04fad5ea0h, 0688fc31ch, 0d1cff191h, 0b3a8c1adh, 02f2f2218h, 0be0e1777h, 0ea752dfeh, 08b021fa1h, 0e5a0cc0fh, 0b56f74e8h, 018acf3d6h, 0ce89e299h
!DD 0b4a84fe0h, 0fd13e0b7h, 07cc43b81h, 0d2ada8d9h, 0165fa266h, 080957705h, 093cc7314h, 0211a1477h, 0e6ad2065h, 077b5fa86h, 0c75442f5h, 0fb9d35cfh
!DD 0ebcdaf0ch, 07b3e89a0h, 0d6411bd3h, 0ae1e7e49h, 000250e2dh, 02071b35eh, 0226800bbh, 057b8e0afh, 02464369bh, 0f009b91eh, 05563911dh, 059dfa6aah
!DD 078c14389h, 0d95a537fh, 0207d5ba2h, 002e5b9c5h, 083260376h, 06295cfa9h, 011c81968h, 04e734a41h, 0b3472dcah, 07b14a94ah, 01b510052h, 09a532915h
!DD 0d60f573fh, 0bc9bc6e4h, 02b60a476h, 081e67400h, 008ba6fb5h, 0571be91fh, 0f296ec6bh, 02a0dd915h, 0b6636521h, 0e7b9f9b6h, 0ff34052eh, 0c5855664h
!DD 053b02d5dh, 0a99f8fa1h, 008ba4799h, 06e85076ah
SBox2:
!DD 04b7a70e9h, 0b5b32944h, 0db75092eh, 0c4192623h, 0ad6ea6b0h, 049a7df7dh, 09cee60b8h, 08fedb266h, 0ecaa8c71h, 0699a17ffh, 05664526ch, 0c2b19ee1h
!DD 0193602a5h, 075094c29h, 0a0591340h, 0e4183a3eh, 03f54989ah, 05b429d65h, 06b8fe4d6h, 099f73fd6h, 0a1d29c07h, 0efe830f5h, 04d2d38e6h, 0f0255dc1h
!DD 04cdd2086h, 08470eb26h, 06382e9c6h, 0021ecc5eh, 009686b3fh, 03ebaefc9h, 03c971814h, 06b6a70a1h, 0687f3584h, 052a0e286h, 0b79c5305h, 0aa500737h
!DD 03e07841ch, 07fdeae5ch, 08e7d44ech, 05716f2b8h, 0b03ada37h, 0f0500c0dh, 0f01c1f04h, 00200b3ffh, 0ae0cf51ah, 03cb574b2h, 025837a58h, 0dc0921bdh
!DD 0d19113f9h, 07ca92ff6h, 094324773h, 022f54701h, 03ae5e581h, 037c2dadch, 0c8b57634h, 09af3dda7h, 0a9446146h, 00fd0030eh, 0ecc8c73eh, 0a4751e41h
!DD 0e238cd99h, 03bea0e2fh, 03280bba1h, 0183eb331h, 04e548b38h, 04f6db908h, 06f420d03h, 0f60a04bfh, 02cb81290h, 024977c79h, 05679b072h, 0bcaf89afh
!DD 0de9a771fh, 0d9930810h, 0b38bae12h, 0dccf3f2eh, 05512721fh, 02e6b7124h, 0501adde6h, 09f84cd87h, 07a584718h, 07408da17h, 0bc9f9abch, 0e94b7d8ch
!DD 0ec7aec3ah, 0db851dfah, 063094366h, 0c464c3d2h, 0ef1c1847h, 03215d908h, 0dd433b37h, 024c2ba16h, 012a14d43h, 02a65c451h, 050940002h, 0133ae4ddh
!DD 071dff89eh, 010314e55h, 081ac77d6h, 05f11199bh, 0043556f1h, 0d7a3c76bh, 03c11183bh, 05924a509h, 0f28fe6edh, 097f1fbfah, 09ebabf2ch, 01e153c6eh
!DD 086e34570h, 0eae96fb1h, 0860e5e0ah, 05a3e2ab3h, 0771fe71ch, 04e3d06fah, 02965dcb9h, 099e71d0fh, 0803e89d6h, 05266c825h, 02e4cc978h, 09c10b36ah
!DD 0c6150ebah, 094e2ea78h, 0a5fc3c53h, 01e0a2df4h, 0f2f74ea7h, 0361d2b3dh, 01939260fh, 019c27960h, 05223a708h, 0f71312b6h, 0ebadfe6eh, 0eac31f66h
!DD 0e3bc4595h, 0a67bc883h, 0b17f37d1h, 0018cff28h, 0c332ddefh, 0be6c5aa5h, 065582185h, 068ab9802h, 0eecea50fh, 0db2f953bh, 02aef7dadh, 05b6e2f84h
!DD 01521b628h, 029076170h, 0ecdd4775h, 0619f1510h, 013cca830h, 0eb61bd96h, 00334fe1eh, 0aa0363cfh, 0b5735c90h, 04c70a239h, 0d59e9e0bh, 0cbaade14h
!DD 0eecc86bch, 060622ca7h, 09cab5cabh, 0b2f3846eh, 0648b1eafh, 019bdf0cah, 0a02369b9h, 0655abb50h, 040685a32h, 03c2ab4b3h, 0319ee9d5h, 0c021b8f7h
!DD 09b540b19h, 0875fa099h, 095f7997eh, 0623d7da8h, 0f837889ah, 097e32d77h, 011ed935fh, 016681281h, 00e358829h, 0c7e61fd6h, 096dedfa1h, 07858ba99h
!DD 057f584a5h, 01b227263h, 09b83c3ffh, 01ac24696h, 0cdb30aebh, 0532e3054h, 08fd948e4h, 06dbc3128h, 058ebf2efh, 034c6ffeah, 0fe28ed61h, 0ee7c3c73h
!DD 05d4a14d9h, 0e864b7e3h, 042105d14h, 0203e13e0h, 045eee2b6h, 0a3aaabeah, 0db6c4f15h, 0facb4fd0h, 0c742f442h, 0ef6abbb5h, 0654f3b1dh, 041cd2105h
!DD 0d81e799eh, 086854dc7h, 0e44b476ah, 03d816250h, 0cf62a1f2h, 05b8d2646h, 0fc8883a0h, 0c1c7b6a3h, 07f1524c3h, 069cb7492h, 047848a0bh, 05692b285h
!DD 0095bbf00h, 0ad19489dh, 01462b174h, 023820e00h, 058428d2ah, 00c55f5eah, 01dadf43eh, 0233f7061h, 03372f092h, 08d937e41h, 0d65fecf1h, 06c223bdbh
!DD 07cde3759h, 0cbee7460h, 04085f2a7h, 0ce77326eh, 0a6078084h, 019f8509eh, 0e8efd855h, 061d99735h, 0a969a7aah, 0c50c06c2h, 05a04abfch, 0800bcadch
!DD 09e447a2eh, 0c3453484h, 0fdd56705h, 00e1e9ec9h, 0db73dbd3h, 0105588cdh, 0675fda79h, 0e3674340h, 0c5c43465h, 0713e38d8h, 03d28f89eh, 0f16dff20h
!DD 0153e21e7h, 08fb03d4ah, 0e6e39f2bh, 0db83adf7h
SBox3:
!DD 0e93d5a68h, 0948140f7h, 0f64c261ch, 094692934h, 0411520f7h, 07602d4f7h, 0bcf46b2eh, 0d4a20068h, 0d4082471h, 03320f46ah, 043b7d4b7h, 0500061afh
!DD 01e39f62eh, 097244546h, 014214f74h, 0bf8b8840h, 04d95fc1dh, 096b591afh, 070f4ddd3h, 066a02f45h, 0bfbc09ech, 003bd9785h, 07fac6dd0h, 031cb8504h
!DD 096eb27b3h, 055fd3941h, 0da2547e6h, 0abca0a9ah, 028507825h, 0530429f4h, 00a2c86dah, 0e9b66dfbh, 068dc1462h, 0d7486900h, 0680ec0a4h, 027a18deeh
!DD 04f3ffea2h, 0e887ad8ch, 0b58ce006h, 07af4d6b6h, 0aace1e7ch, 0d3375fech, 0ce78a399h, 0406b2a42h, 020fe9e35h, 0d9f385b9h, 0ee39d7abh, 03b124e8bh
!DD 01dc9faf7h, 04b6d1856h, 026a36631h, 0eae397b2h, 03a6efa74h, 0dd5b4332h, 06841e7f7h, 0ca7820fbh, 0fb0af54eh, 0d8feb397h, 0454056ach, 0ba489527h
!DD 055533a3ah, 020838d87h, 0fe6ba9b7h, 0d096954bh, 055a867bch, 0a1159a58h, 0cca92963h, 099e1db33h, 0a62a4a56h, 03f3125f9h, 05ef47e1ch, 09029317ch
!DD 0fdf8e802h, 004272f70h, 080bb155ch, 005282ce3h, 095c11548h, 0e4c66d22h, 048c1133fh, 0c70f86dch, 007f9c9eeh, 041041f0fh, 0404779a4h, 05d886e17h
!DD 0325f51ebh, 0d59bc0d1h, 0f2bcc18fh, 041113564h, 0257b7834h, 0602a9c60h, 0dff8e8a3h, 01f636c1bh, 00e12b4c2h, 002e1329eh, 0af664fd1h, 0cad18115h
!DD 06b2395e0h, 0333e92e1h, 03b240b62h, 0eebeb922h, 085b2a20eh, 0e6ba0d99h, 0de720c8ch, 02da2f728h, 0d0127845h, 095b794fdh, 0647d0862h, 0e7ccf5f0h
!DD 05449a36fh, 0877d48fah, 0c39dfd27h, 0f33e8d1eh, 00a476341h, 0992eff74h, 03a6f6eabh, 0f4f8fd37h, 0a812dc60h, 0a1ebddf8h, 0991be14ch, 0db6e6b0dh
!DD 0c67b5510h, 06d672c37h, 02765d43bh, 0dcd0e804h, 0f1290dc7h, 0cc00ffa3h, 0b5390f92h, 0690fed0bh, 0667b9ffbh, 0cedb7d9ch, 0a091cf0bh, 0d9155ea3h
!DD 0bb132f88h, 0515bad24h, 07b9479bfh, 0763bd6ebh, 037392eb3h, 0cc115979h, 08026e297h, 0f42e312dh, 06842ada7h, 0c66a2b3bh, 012754ccch, 0782ef11ch
!DD 06a124237h, 0b79251e7h, 006a1bbe6h, 04bfb6350h, 01a6b1018h, 011caedfah, 03d25bdd8h, 0e2e1c3c9h, 044421659h, 00a121386h, 0d90cec6eh, 0d5abea2ah
!DD 064af674eh, 0da86a85fh, 0bebfe988h, 064e4c3feh, 09dbc8057h, 0f0f7c086h, 060787bf8h, 06003604dh, 0d1fd8346h, 0f6381fb0h, 07745ae04h, 0d736fccch
!DD 083426b33h, 0f01eab71h, 0b0804187h, 03c005e5fh, 077a057beh, 0bde8ae24h, 055464299h, 0bf582e61h, 04e58f48fh, 0f2ddfda2h, 0f474ef38h, 08789bdc2h
!DD 05366f9c3h, 0c8b38e74h, 0b475f255h, 046fcd9b9h, 07aeb2661h, 08b1ddf84h, 0846a0e79h, 0915f95e2h, 0466e598eh, 020b45770h, 08cd55591h, 0c902de4ch
!DD 0b90bace1h, 0bb8205d0h, 011a86248h, 07574a99eh, 0b77f19b6h, 0e0a9dc09h, 0662d09a1h, 0c4324633h, 0e85a1f02h, 009f0be8ch, 04a99a025h, 01d6efe10h
!DD 01ab93d1dh, 00ba5a4dfh, 0a186f20fh, 02868f169h, 0dcb7da83h, 0573906feh, 0a1e2ce9bh, 04fcd7f52h, 050115e01h, 0a70683fah, 0a002b5c4h, 00de6d027h
!DD 09af88c27h, 0773f8641h, 0c3604c06h, 061a806b5h, 0f0177a28h, 0c0f586e0h, 0006058aah, 030dc7d62h, 011e69ed7h, 02338ea63h, 053c2dd94h, 0c2c21634h
!DD 0bbcbee56h, 090bcb6deh, 0ebfc7da1h, 0ce591d76h, 06f05e409h, 04b7c0188h, 039720a3dh, 07c927c24h, 086e3725fh, 0724d9db9h, 01ac15bb4h, 0d39eb8fch
!DD 0ed545578h, 008fca5b5h, 0d83d7cd3h, 04dad0fc4h, 01e50ef5eh, 0b161e6f8h, 0a28514d9h, 06c51133ch, 06fd5c7e7h, 056e14ec4h, 0362abfceh, 0ddc6c837h
!DD 0d79a3234h, 092638212h, 0670efa8eh, 0406000e0h
SBox4:
!DD 03a39ce37h, 0d3faf5cfh, 0abc27737h, 05ac52d1bh, 05cb0679eh, 04fa33742h, 0d3822740h, 099bc9bbeh, 0d5118e9dh, 0bf0f7315h, 0d62d1c7eh, 0c700c47bh
!DD 0b78c1b6bh, 021a19045h, 0b26eb1beh, 06a366eb4h, 05748ab2fh, 0bc946e79h, 0c6a376d2h, 06549c2c8h, 0530ff8eeh, 0468dde7dh, 0d5730a1dh, 04cd04dc6h
!DD 02939bbdbh, 0a9ba4650h, 0ac9526e8h, 0be5ee304h, 0a1fad5f0h, 06a2d519ah, 063ef8ce2h, 09a86ee22h, 0c089c2b8h, 043242ef6h, 0a51e03aah, 09cf2d0a4h
!DD 083c061bah, 09be96a4dh, 08fe51550h, 0ba645bd6h, 02826a2f9h, 0a73a3ae1h, 04ba99586h, 0ef5562e9h, 0c72fefd3h, 0f752f7dah, 03f046f69h, 077fa0a59h
!DD 080e4a915h, 087b08601h, 09b09e6adh, 03b3ee593h, 0e990fd5ah, 09e34d797h, 02cf0b7d9h, 0022b8b51h, 096d5ac3ah, 0017da67dh, 0d1cf3ed6h, 07c7d2d28h
!DD 01f9f25cfh, 0adf2b89bh, 05ad6b472h, 05a88f54ch, 0e029ac71h, 0e019a5e6h, 047b0acfdh, 0ed93fa9bh, 0e8d3c48dh, 0283b57cch, 0f8d56629h, 079132e28h
!DD 0785f0191h, 0ed756055h, 0f7960e44h, 0e3d35e8ch, 015056dd4h, 088f46dbah, 003a16125h, 00564f0bdh, 0c3eb9e15h, 03c9057a2h, 097271aech, 0a93a072ah
!DD 01b3f6d9bh, 01e6321f5h, 0f59c66fbh, 026dcf319h, 07533d928h, 0b155fdf5h, 003563482h, 08aba3cbbh, 028517711h, 0c20ad9f8h, 0abcc5167h, 0ccad925fh
!DD 04de81751h, 03830dc8eh, 0379d5862h, 09320f991h, 0ea7a90c2h, 0fb3e7bceh, 05121ce64h, 0774fbe32h, 0a8b6e37eh, 0c3293d46h, 048de5369h, 06413e680h
!DD 0a2ae0810h, 0dd6db224h, 069852dfdh, 009072166h, 0b39a460ah, 06445c0ddh, 0586cdecfh, 01c20c8aeh, 05bbef7ddh, 01b588d40h, 0ccd2017fh, 06bb4e3bbh
!DD 0dda26a7eh, 03a59ff45h, 03e350a44h, 0bcb4cdd5h, 072eacea8h, 0fa6484bbh, 08d6612aeh, 0bf3c6f47h, 0d29be463h, 0542f5d9eh, 0aec2771bh, 0f64e6370h
!DD 0740e0d8dh, 0e75b1357h, 0f8721671h, 0af537d5dh, 04040cb08h, 04eb4e2cch, 034d2466ah, 00115af84h, 0e1b00428h, 095983a1dh, 006b89fb4h, 0ce6ea048h
!DD 06f3f3b82h, 03520ab82h, 0011a1d4bh, 0277227f8h, 0611560b1h, 0e7933fdch, 0bb3a792bh, 0344525bdh, 0a08839e1h, 051ce794bh, 02f32c9b7h, 0a01fbac9h
!DD 0e01cc87eh, 0bcc7d1f6h, 0cf0111c3h, 0a1e8aac7h, 01a908749h, 0d44fbd9ah, 0d0dadecbh, 0d50ada38h, 00339c32ah, 0c6913667h, 08df9317ch, 0e0b12b4fh
!DD 0f79e59b7h, 043f5bb3ah, 0f2d519ffh, 027d9459ch, 0bf97222ch, 015e6fc2ah, 00f91fc71h, 09b941525h, 0fae59361h, 0ceb69cebh, 0c2a86459h, 012baa8d1h
!DD 0b6c1075eh, 0e3056a0ch, 010d25065h, 0cb03a442h, 0e0ec6e0eh, 01698db3bh, 04c98a0beh, 03278e964h, 09f1f9532h, 0e0d392dfh, 0d3a0342bh, 08971f21eh
!DD 01b0a7441h, 04ba3348ch, 0c5be7120h, 0c37632d8h, 0df359f8dh, 09b992f2eh, 0e60b6f47h, 00fe3f11dh, 0e54cda54h, 01edad891h, 0ce6279cfh, 0cd3e7e6fh
!DD 01618b166h, 0fd2c1d05h, 0848fd2c5h, 0f6fb2299h, 0f523f357h, 0a6327623h, 093a83531h, 056cccd02h, 0acf08162h, 05a75ebb5h, 06e163697h, 088d273cch
!DD 0de966292h, 081b949d0h, 04c50901bh, 071c65614h, 0e6c6c7bdh, 0327a140ah, 045e1d006h, 0c3f27b9ah, 0c9aa53fdh, 062a80f00h, 0bb25bfe2h, 035bdd2f6h
!DD 071126905h, 0b2040222h, 0b6cbcf7ch, 0cd769c2bh, 053113ec0h, 01640e3d3h, 038abbd60h, 02547adf0h, 0ba38209ch, 0f746ce76h, 077afa1c5h, 020756060h
!DD 085cbfe4eh, 08ae88dd8h, 07aaaf9b0h, 04cf9aa7eh, 01948c25ch, 002fb8a8ch, 001c36ae4h, 0d6ebe1f9h, 090d4f869h, 0a65cdea0h, 03f09252dh, 0c208e69fh
!DD 0b74e6132h, 0ce77e25bh, 0578fdfe3h, 03ac372e6h
EDIT :
in the above code, replace the middle with :
Code: Select all
buff.s = PeekS(*mem1)
FreeMemory(*mem0)
FreeMemory(*mem1)
*mem0=AllocateMemory(4096)
*mem1=AllocateMemory(4096)
PokeS(*mem1, buff)
Unfortunaly, in real program use, the "FreeMemory" means that we do not
encrypted the text, we just start after, with the encrypted form, to decrypt.
Is the code buggy and not reliable or do I miss something ?
- Registered PB user -
Using PB 4.00
Using PB 4.00
Sorry to spam the forum, it's just to make things clearer and easier to read.
Now I am using the excellent library from SEC, very easier to use, I wonder why I didn't start to use his one from start :roll:
Anyway, I have the same error, but the code is more readable, I hope someone will be able to tell me what's wrong :
here a screenshot of the problem :

Now I am using the excellent library from SEC, very easier to use, I wonder why I didn't start to use his one from start :roll:
Anyway, I have the same error, but the code is more readable, I hope someone will be able to tell me what's wrong :
Code: Select all
Global TextLenght
#CRYPT_BUFFER_SIZE = 4096
Text$="maximum t limité dans les 500 caractères" : Debug Text$
temp.s = "toto" : temp = MD5Fingerprint(temp, Len(temp)) : temp + "aaaaaaaaaaaaaaaaaaaaaaaa"
;=> 32 + 24 = 56 characters * 8 = 448 bits
bfinit(temp,56)
TextLenght = Len(Text$)
Debug "Len(Text$) = " + Str(TextLenght )
Procedure.s Encrypt(*Buffer)
*Crypt = AllocateMemory(#CRYPT_BUFFER_SIZE)
For a = 0 To TextLenght Step 8
bfencrypt(*Crypt+a,*Buffer+a)
;Debug "a = " + Str(a)
Next a
ProcedureReturn PeekS(*Crypt)
EndProcedure
Procedure.s Decrypt(*Buffer)
*Decrypt = AllocateMemory(#CRYPT_BUFFER_SIZE)
For a=0 To TextLenght Step 8
bfdecrypt(*Decrypt + a, *Buffer + a)
Next a
ProcedureReturn PeekS(*Decrypt)
EndProcedure
enc.s = Encrypt(@Text$)
Debug "my proc : crypt = " + enc
Debug "my proc : decrypt = " + Decrypt(@enc)
Debug " "
- Registered PB user -
Using PB 4.00
Using PB 4.00
No, registered full version of PB v3.91
EDIT :
for those whishing to do tests (I hope at least Sec
), there is another one which bug :
to replace on the code above based on the Sec's Lib, you will notice that the final "_" is missing after the decryption.
Most of the time the decrytion is ok, but sometimes (tested on different typical french sentences) it does not decrypt correctly.
Still searching why...
EDIT :
for those whishing to do tests (I hope at least Sec
Code: Select all
Text$="é'èjfcisduhfj'é_èyjcidufyjcé_èrcjoriycjé'_" : Debug Text$
Most of the time the decrytion is ok, but sometimes (tested on different typical french sentences) it does not decrypt correctly.
Still searching why...
- Registered PB user -
Using PB 4.00
Using PB 4.00
-
sec
- Enthusiast

- Posts: 792
- Joined: Sat Aug 09, 2003 3:13 am
- Location: 90-61-92 // EU or ASIA
- Contact:
Problem comes from your procudure Encrypt
*Crypt point to raw bytes (include byte $0)
PeekS can't read bytes after $0 because $0 is define as terminal for a string.
Code: Select all
Procedure.s Encrypt(*Buffer)
..
ProcedureReturn [b]PeekS(*Crypt) [/b]
EndProcedure PeekS can't read bytes after $0 because $0 is define as terminal for a string.
Wow, very good point !
you are the man of the year Sec
Nice Lib, and nice advices
Your answer is near to give me the solution, and the problem is :
how can I know the size of the memory pointer containing the encrypted data ?
sizeof(*Buffer) returns a value far too small (4)
len(peeks(*Buffer)) as you stated won't read until the end of the data, but until the end character (which is not necessarely the end of the data).
In the Loop, I must decrypt until the end position, which is the size of the buffer.
It's probably a trivial memory basic command I need, but he, am I not a "newbie"
Still, great help from you.
you are the man of the year Sec
Nice Lib, and nice advices
Your answer is near to give me the solution, and the problem is :
how can I know the size of the memory pointer containing the encrypted data ?
sizeof(*Buffer) returns a value far too small (4)
len(peeks(*Buffer)) as you stated won't read until the end of the data, but until the end character (which is not necessarely the end of the data).
In the Loop, I must decrypt until the end position, which is the size of the buffer.
It's probably a trivial memory basic command I need, but he, am I not a "newbie"
Still, great help from you.
- Registered PB user -
Using PB 4.00
Using PB 4.00
solution : GlobalSize_(*Buffer)
This API solves the problem.
EDIT :
in fact not always, it was working on my debugging procedure becaus eit was a particular case.
As a workaround I always set the buffer size to 512 and I always keep it, so I always read 512 bytes and it works.
Now I am facing many memory troubles but that another story
This API solves the problem.
EDIT :
in fact not always, it was working on my debugging procedure becaus eit was a particular case.
As a workaround I always set the buffer size to 512 and I always keep it, so I always read 512 bytes and it works.
Now I am facing many memory troubles but that another story
- Registered PB user -
Using PB 4.00
Using PB 4.00

