<< Click to Display Table of Contents >> Navigation: 3. Script Language > Encryption and Hash Functions > Encryption and Hashing Commands |
MiniRobotLanguage (MRL)
GMD. Command
Get Message Digest
Intention
This command returns the checksum of a string or a file. If you are not sure what a checksum is, or what it is good for, read this WEB-Link: Checksum.
Lets start with the checksum of a string:
: $$TXT=Smart
GMD.|$$TXT|$$TXT
MBX.The text checksum is:$crlf$$$TXT
For this simple operation, no prototypes are needed.
The result is a hexadecimal checksum (see picture below) that used an FNV32 algo. This is the default algorithm, if no other algorithm is selected.
We can give some prototypes to change the checksum algo or the output format. Like this:
GMD.d|$$TXT|$$TXT
The result is the same number as decimal number. See following picture.
Now lets choose another checksum algo. Lets try MD5.
MD5 will always return such a long hexadezimal string. It will ignore other options.
Next, lets take a checksum from a file. It's as simple as before. We just give the prototype "f" and the first variable contains the filename.
: $$FIL=?desktop\New_Update.zip
GMD.vf|$$FIL|$$TXT
This way you can easily make a file integrity check of any file!
Now let's do some ...
Speed considerations:
For a file with a size of >100 MB i get a checksum-time of about 0.3 seconds.
' Checksum-time FNV32: 0.3 seconds
GMD.vf|$$FIL|$$TXT
' Checksum-time Elf32: 0.5 seconds
GMD.ef|$$FIL|$$TXT
' Checksum-time CRC-32: 0.5 seconds
GMD.cf|$$FIL|$$TXT
As we can see, this checksums does not cost you a lot of time. But how about MD5?
' Checksum-time MD5: 97.5 seconds
GMD.mf|$$FIL|$$TXT
MD5 may eat a full second per Megabyte, depending on the speed of your system.
But even this is a very good time!
Now this speed can only be reached, because we hold the complete data in computer memory in one piece.
For very large files (>500 MB? or >1 GB? this depends on your memory situation) this is not possible. If you need checksums of large files, choose the option "b" or for special uses "s".
' Get Checksum from Textfile
VAR.$$TIM=#dtime#
GMD.s|$$FIL|$$TXT
MBX.The file checksum is:$crlf$$$TXT$crlf$Used time:#dsince# seconds.
ENR.
Syntax
GMD.P1|P2[|P3]
Parameter Explanation
P1 - VAR/Prototypes
Prototypes must consist of one or two letters.
The first letter shall be:
f - input from file, if omitted input is taken from variable
b - file is bigger then System RAM, choose slower "block-by block" algorithm. This option (unlike f or s) does not support
a second letter. It will also work for small files, as it will internally switch to another algo if the file is small.
s - calculate a string checkum from a long file. This Option is similar to "b" but the result is much more exact.
Result is a string with a checksum for each 8192 characters of the source-file. This option (unlike f or s) does
not support a second letter. It may return a large checksum-string.
All of the following prototypes will be ignored when options "b" or "s" are used:
v - use FNV32 Hash (default if omitted).
c - use CRC32 Hash.
e - use Elf 32 Hash.
m - use the MD5 checksum (slower, more safe). Result is a string.
All of the following prototypes will be ignored when option "s" or "m" is used:
h - Hexadecimal Output as string (default if omitted)
o - Octal Output as string
d - Decimal Output
i - Binary Output as string
P2 - VAR with the String or the Filename to process
P3 - optional VAR for Result, if omitted TOS is used
Example
-
Remarks
-
Limitations:
File-Size
File-Size is limited by System RAM, and generally to a maximum of 2 GB (32 bit), unless the option b or s is specified. These Options should be able to handle any possible file-size (64 bit).
See also: