[Implemented] More flexible cipher lib commands please

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

[Implemented] More flexible cipher lib commands please

Post by va!n »

It would be very nice to have the posiblity to do a CRC32 fingerprint directly on files (even on very big files instead reading the big files into memory)

In this case i would like to have an advanced version for such commands to define the start- and endpostion of a file. What dd you think about this?

CRC32FileFingerprint(filename$, [startpos, endpos])
MD5FileFingerprint(Filename$, [startpos, endpos])
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

i second the request and an initial parameter would be also very usefull. as far as i can remember, fred said 4 years ago that he will implement this "soon". :cry:

Code: Select all

CRC32Fingerprint(Buffer, Length, Initial)
MD5Fingerprint(Buffer, Length, Initial)
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

For the "Initial" stuff, it's like doing Buffer+Initial no ? Or I miss something obvious ?
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

i mean initial like in this code by horst:

Code: Select all

; ---------------------------------------------------------------
; CRC32 Calculation - supports handling file by chunks 
; Note: The CRC table is initialized at startup 
; by Horst Schaeffer - horst.schaeffer@gmx.net
; ---------------------------------------------------------------

;  Note: CRC of a file can be computed ..
;  (1) by reading the complete file into a memory buffer 
;      Parameters: *Memory,Size,0  (initial CRC = 0)
;  (2) by reading portions of the file: the CRC of the previous 
;      portion is always used as starting value for the next 
;      portion; initial CRC = 0
; ---------------------------------------------------------------
; initialize

*CRCtable  = AllocateMemory(1024)
*CRCpoint.long = *CRCtable
For index = 0 To 255 
  Value = index 
  For i = 1 To 8 
    LSB = Value & 1
    Value >> 1  & $7FFFFFFF
    If LSB : Value ! $EDB88320 : EndIf 
  Next 
  *CRCpoint\l = Value : *CRCpoint + 4
Next 

;  Compute CRC32 for data area given by *Memory pointer and Size,
;  and InitialCRC from last chunk (first time: 0) 
;  returns (new) CRC

Procedure CRC32compute(*Memory.byte,Size,InitialCRC)
  Shared *CRCtable 
  Protected CRC.l, *CRCpoint.long
  CRC = ~InitialCRC
  While Size 
    Value = ((CRC ! *Memory\b) & $FF) << 2
    CRC >> 8 & $00FFFFFF
    *CRCpoint = *CRCtable + Value 
    CRC ! *CRCpoint\l 
    *Memory +1 : Size -1 
  Wend  
ProcedureReturn ~CRC
EndProcedure 
so we could use the last crc32 chunk as starting value for the next chunk and so on.

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

That makes sens.
Post Reply