axLib / little helper library for easy encryption/hash usage

Developed or developing a new product in PureBasic? Tell the world about it.
Max.²
Enthusiast
Enthusiast
Posts: 175
Joined: Wed Jul 28, 2004 8:38 am

axLib / little helper library for easy encryption/hash usage

Post by Max.² »

Updated August 19/2004.

No worries, I will slow down again. :wink:

One thing that bothered me most with all the encryption and hash libs was the bad handling of keys and such. I made a little helper library therefor:

axLib - http://www.host4scripts.de/pub/axLib.zip

Here the code I previously used:

Code: Select all

;the old way:
HexString.s = "10E06B990D44DE0091A2113FD95C92FC905166AF147AA7632639C41AA7F26B1620C47443813C605B924C05591C161ECC35944FC69C4433A49D10FC6B04A33611"

BufferSize  = Len(HexString.s)/2

*Buffer = AllocateMemory(BufferSize)

;poke the hexstring into the buffer, 2 characters  of HexString are one value in memory
;procedure from PB / english forum - we need that as helper
Procedure.l hex2dec(h$) 
  
  h$=UCase(h$) 
  For r=1 To Len(h$) 
    d<<4 : a$=Mid(h$,r,1) 
    If Asc(a$)>60 
      d+Asc(a$)-55 
    Else 
      d+Asc(a$)-48 
    EndIf 
  Next 
  
  ProcedureReturn d 
    
EndProcedure 

j=-1 
For i=1 To Len(HexString) Step 2  
  j=j+1 
  PokeB(*Buffer+j,Hex2Dec(Mid(HexString.s,i,2)))      
Next i

;let's show the buffer in hexa again
;Result.s=axBufferToHexString(*Buffer,Buffersize)
For i=1 To BufferSize
  Result.s = Result.s+RSet(Hex(PeekB(*Buffer+i-1) & $FF),2,"0")
Next i
Debug Result

;just here for reference to the third function in the other sample
Decimal = Hex2Dec("A0")
Debug Decimal
The same can be done now that way:

Code: Select all

;axLib - http://www.host4scripts.de/pub/axLib.zip

HexString.s = "10E06B990D44DE0091A2113FD95C92FC905166AF147AA7632639C41AA7F26B1620C47443813C605B924C05591C161ECC35944FC69C4433A49D10FC6B04A33611"

BufferSize  = Len(HexString.s)/2

*Buffer = AllocateMemory(BufferSize)

;poke the hexstring into the buffer, 2 characters  of HexString are one value in memory
axHexStringToBuffer(HexString.s,*Buffer)

;let's show the buffer in hexa again
Result.s=axBufferToHexString(*Buffer,Buffersize)
Debug Result.s

;sideproduct of the above routines. Takes just one byte, but is relatively fast.
Decimal = axHexByteStringToDecimal("A0")
Debug Decimal
Hope this can help you!
Last edited by Max.² on Thu Aug 19, 2004 10:06 pm, edited 3 times in total.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

That's exactly what I need ! :P

but your link does not work for now :?

pls fix it :)

EDIT : it's ok now, downloading it ^^
- Registered PB user -

Using PB 4.00
Max.²
Enthusiast
Enthusiast
Posts: 175
Joined: Wed Jul 28, 2004 8:38 am

Post by Max.² »

Sorry, link fixed.

See, yesterday I drank 1 bottle Martini and 2/3 bottle Limes. Then I finished the SHA lib, uploaded it, fixed a bug. Everything ok.

Today I didn't drink any alcohol, and I can't even upload correctly. Shall I be concerned? :twisted:
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

My code does not work :

Code: Select all

BFkey.s = "10E06B990D44DE0091A2113FD95C92FC905166AF147AA7632639C41AA7F26B1620C47443813C605B924C05591C161ECC35944FC69C4433A49D10FC6B04A33611"
BufferSize.l = Len(BFkey)/2
*Buffer1 = AllocateMemory(BufferSize)

;poke the hexstring into the buffer, 2 characters  of HexString are one value in memory
axHexStringToBuffer(BFkey, *Buffer1)

;let's show the buffer in hexa again
Result.s=axBufferToHexString(*Buffer1, BufferSize)
Debug Result.s
it returns :

Code: Select all

101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F

any idea why ?
- Registered PB user -

Using PB 4.00
Max.²
Enthusiast
Enthusiast
Posts: 175
Joined: Wed Jul 28, 2004 8:38 am

Post by Max.² »

newbie wrote:My code does not work :

Code: Select all

any idea why ?[/quote]

Likely I made an error. Told you that not drinking isn't the solution.  :lol:
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

LOL :lol:

please drink water/alcohol or wathever now, this helper lib would be really usefull if working ;)
- Registered PB user -

Using PB 4.00
Max.²
Enthusiast
Enthusiast
Posts: 175
Joined: Wed Jul 28, 2004 8:38 am

Post by Max.² »

Think I found the bug and uploaded new version.

Hope it works now & thanks for testing!

Grr. Nope. Worked once. Worked twice and now it stopped doing...
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

np for testing ;)

now it returns :

Code: Select all

101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F
still the wrong code.
Please drink some Martini again if needed to correct it, you have my permission ;)

Bed time now.

EDIT : in case of doubts, the MD5 of the lib I am using is :
CFDA62705B7DABE10619364DE5941C98

(not the zip file, just the lib)
- Registered PB user -

Using PB 4.00
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Post by sec »

newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

Yes Sec, but it is not more different than actually, I mean you have to add at least one function in the code, and I like to simplify the code and to just have one line while putting the key in the buffer :)

For sure even actually without any lib it works, but if the same can be done
in one line, and that the lib is fast and tiny (don't make the executable too big) then I like this ;)
- Registered PB user -

Using PB 4.00
Max.²
Enthusiast
Enthusiast
Posts: 175
Joined: Wed Jul 28, 2004 8:38 am

Post by Max.² »

Sorry it took so long, but the house needed a bit of loving. :?

I updated the archive after removing the really really stupid bug. Hope it works now for any buffer, not only for ones with values<128. :twisted: :wink:

http://www.host4scripts.de/pub/axLib.zip
Post Reply