Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieve values from the Checksum (sys(2017))
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Network:
Windows 2000 Pro
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01018348
Message ID:
01023710
Views:
10
Hi Ravi,

You're reinventing the wheel. Your code seems to do exactly what sys(2017) would do.

Also, the checksum function is irreversible. In other words, you cannot infere the data from the checksum value.

Let me give you a very simple example:

The tracking numbers for DHL are always multiples of 11. A simple checksum approach for them would be:
if trackingNumber % 11 <> 0
messagebox("This tracking number is incorrect")
endif

In essence, in the above scenario, the checksum function is "MOD", and the only valid checksum is 0 (zero). If I tell you that I have a dhl tracking number with a checksum = 0, all you can tell from that, knowing the checksum function is that the tracking number I have is a multiple of 11, but you can't tell me what number I have.

In essence, checksums are used for storing passwords (you just store the checksum of the password and when the user logs in you compare the checksum you have with the one your program just calculated), thus making the system immune to theft of passwords by stealing the database, they're used for error detection (and sometimes correction) like in the dhl example above, or as a quick way to flag records or fields whose values changed without the need to store the actual values.

Another very simplistic way to generate a checksum for a record is to add up ALL the ascii values of ALL the characters and doing a mod 256 operation on them. You have just obtained a 1-byte checksum of a string that could be 1500 bytes long.

If any character changes in the record, your checksum will change too.

Note that 2 or more strings can have the same checksum. This is VERY VERY important because this little phenomenon can break your code.

Have fun!

Alex



>Hi !
>
>Sorry! It is by mistake I've mentioned the SYS(2017) in place of SYS(2007).
>
>I'm using SYS(2007) for getting the checksum value of the records. Pls check the below mentioned function. In this function, I'm storing the data of all the fields in a variable and then generating a checksum value with the help of SYS(2007).
>
>My question is ;
>Is this possible to retrieve the fields data from the checksum value.
>
>
>* ----------------------- *
>FUNCTION CheckSum
>* ----------------------- *
>nFldcount = AFIELDS(aFldArray) && Creating an array and storing the field names
>mFld = ''
>FOR nCnt = 1 to nFldcount
> IF ALLT(UPPE(aFldArray(ncnt,1))) # "CHKSUM"
> IF nCnt = 1
> mFld = 'STR('+ALLTRIM(UPPER(aFldArray(nCnt,1)))+')'
> LOOP
> ENDIF
>
> DO CASE
> CASE aFldArray(nCnt,2) = 'T' OR aFldArray(ncnt,2) = 'D'
> mFld = mFld + '+DTOS(' + ALLTRIM(UPPER(aFldArray(nCnt,1))) +')'
> CASE aFldArray(nCnt,2) = 'N' OR aFldArray(nCnt,2) = 'I'
> mFld = mFld + '+STR(' +ALLTRIM(UPPER(aFldArray(nCnt,1))) +')'
> CASE aFldArray(nCnt,2) = 'L'
> mFld = mFld + '+' +IIF(&aFldArray(nCnt,1),"'T'","'F'")
> OTHERWISE
> mFld = mFld + '+' +ALLTRIM(UPPER(aFldArray(nCnt,1)))
> ENDCASE
> ENDIF
>ENDFOR
>RETURN (SYS(2007,&mFld))
Low-carb diet not working? Try the Low-food diet instead!
Previous
Reply
Map
View

Click here to load this message in the networking platform