Here a 16 bit CheckSum is represented as the High and Low bytes. The first byte is multiplied by 256 and then BXORed with 0. The result is BANDed with $8000. If there is a 1 in the 16th bit the result is multiplied by 2 then BXORed with $1021, then the result is run through that process 7 more times. Then the second byte is BXORed with that result and that result is processed 8 times. This is repeated until all bits are done. Then we divide the 16 bits into two values, the High and Low CheckSum Bytes. The High by dividing and the Low by BANDing.
This example I found in paper "Bitwise Operations".
A correct implementation of MD5 for NetLinx would be great. I found one a long time ago but it only worked for content with a maximum length of 120 characters :-(
An implementation of Base64 can be found in i!-EquipmentMonitor, which is an "integration! Solutions" application and available for download from the AMX web site.
Take a look at i!-EquipmentMonitorOut.axi. The Base64 function included there is used for SMTP authentication (for sending emails from NetLinx).
If you really need to use MD5 there is a module that I wrote that will perform MD5 encryption. Wont give the source code for the module away for various reasons, but I will send you the token. Just email me...
Below is how to use the module...
DEFINE_VARIABLE
CHAR cTestSecret[] = 'ANY OLD SECRET'
DEFINE_START
DEFINE_MODULE 'Cypher Module' modCypher(vdvCypher);
DEFINE_EVENT
BUTTON_EVENT[dvTP,0]
{
PUSH:
{
// Request Module to Encrypt MD5
SEND_COMMAND vdvCypher,"'CYPHER-',cTestSecret";
// Wait until the response from the module
Wait_Until (LENGTH_STRING(cCypher)) 'Test'
{
// Tests if Response is valid.
SEND_COMMAND vdvCypher,"'CYPHER TEST-',cTestSecret,',',cCypher";
cCypher = "";
}
}
}
DATA_EVENT[vdvCypher]
{
COMMAND:
{
STACK_VAR CHAR cTrash[100];
SELECT
{
// Encrypted Secret
ACTIVE (FIND_STRING(DATA.TEXT,'CYPHER-',1)):
{
cTrash = REMOVE_STRING(DATA.TEXT,'CYPHER-',1);
cCypher = Data.Text
}
// Test 'PASSED' or 'FAILED'
ACTIVE (FIND_STRING(DATA.TEXT,'CYPHER TEST-',1)):
{
SEND_STRING 0,DATA.TEXT
}
}
}
}
MD5 is actually surprisingly simple... my suggestion is to start from a Javascript implementation and translate it into NetLinx. Here is one example: http://pajhome.org.uk/crypt/md5/
Hi,
I'm trying to implement the CRC16-CITT lookup as shown in the example, but getting a "Converting type [Long] to [INTEGER] when compiling. Sorry if this is a basic question, but really keen to use this checksum
Hi,
I'm trying to implement the CRC16-CITT lookup as shown in the example, but getting a "Converting type [Long] to [INTEGER] when compiling.
Are you referring to the code that AMXJeff posted on 01/31? It compiles fine for me if you copy the code exactly as is. You should only get the Long to Integer warning if you leave out the TYPE_CAST.
I was having an issue with the code posted by kphlight 07-31-2006. Specifically the CRC16-CITT table.
its this line that seems to be causing the issue with Converting type [Long] to [INTEGER]
m_crc16c = g_pCRC16CcittTable[((m_crc16c >> 8) ^ crcString16c)+1] ^ (m_crc16c << 8);
I was having an issue with the code posted by kphlight 07-31-2006. Specifically the CRC16-CITT table.
its this line that seems to be causing the issue with Converting type [Long] to [INTEGER]
m_crc16c = g_pCRC16CcittTable[((m_crc16c >> 8) ^ crcString16c)+1] ^ (m_crc16c << 8);
This is actually documented as a CRC16-CITT checksum as well...
Does anyone has a working example / function how to build CRC16-x25?
This is an example that I should calculate.
$00,$00,$03,$00,$12,$6c,$a5,$00,$00,$31,$31,$31,$31,$31,$31,$31,$31,$00 CRC low - CRC high ($D6,$2C)
Thanx.
Comments
Let?s look a t an example of a Cyclical Redundency Checking (CRC) CheckSum:
DEFINE_CALL 'CRC CALC' (LENGTH,STRING[30],H_CRC,L_CRC)
LOCAL_VAR COUNT1 COUNT2 CRC
{
CRC = 0
COUNT1 = 1
WHILE ( COUNT1 <= LENGTH )
{
COUNT2 = 1
CRC = CRC BXOR (STRING[COUNT1] * 256)
WHILE (COUNT2 < 9)
{
IF (CRC BAND $8000)
CRC = (CRC *2) BXOR $1021
ELSE
CRC = CRC * 2
COUNT2 = COUNT2 + 1
}
COUNT1 = COUNT1 + 1
}
H_CRC = CRC/256
L_CRC = CRC BAND 255
}
Here a 16 bit CheckSum is represented as the High and Low bytes. The first byte is multiplied by 256 and then BXORed with 0. The result is BANDed with $8000. If there is a 1 in the 16th bit the result is multiplied by 2 then BXORed with $1021, then the result is run through that process 7 more times. Then the second byte is BXORed with that result and that result is processed 8 times. This is repeated until all bits are done. Then we divide the 16 bits into two values, the High and Low CheckSum Bytes. The High by dividing and the Low by BANDing.
This example I found in paper "Bitwise Operations".
Edited: Use code below
Edited: Use code below
I testet the code from kphlight because i have very much strings to transmit & calculate.
It looks like the fastest way....
But i get some Errors:
Ref Error ^CRC16_LOOKUP Index 0 Line=135
DoNumberExpression - Error 2 Tk=0x2012 Line=135
GetNumber - Error 1 Tk=0x0000
RunCode - Address Mismatch 0x4050 0x000704 0x000706
The problem ist, that the (t = (crc16retVal / 16) BXOR crcString ) returns "516" or "0"
Is the initializer with $FFFF correct???
Greetings & thanx fo help:
Lukas
Here are cleaner chksum functions with lookup tables. It includes:
CRC16 (function crc16)
CRC16.CCITT (function crc16c)
CRC16.XMODEM (function crc16x)
CRC32 (function crc32)
I'm thinking about doing MD2/4/5, SHA1/256/384/512, Base64, CRC64.. anyone have any need of those?
I'd love an MD5. :-)
An implementation of Base64 can be found in i!-EquipmentMonitor, which is an "integration! Solutions" application and available for download from the AMX web site.
Take a look at i!-EquipmentMonitorOut.axi. The Base64 function included there is used for SMTP authentication (for sending emails from NetLinx).
Regards, Harald
If you really need to use MD5 there is a module that I wrote that will perform MD5 encryption. Wont give the source code for the module away for various reasons, but I will send you the token. Just email me...
Below is how to use the module...
Jeremy
Hello,
does anyone has an example for CRC16-checksum with a polynom 1002 ?
many thanks for help
I'm trying to implement the CRC16-CITT lookup as shown in the example, but getting a "Converting type [Long] to [INTEGER] when compiling. Sorry if this is a basic question, but really keen to use this checksum
Cheers
nCRC = TYPE_CAST(nCRC << 1); //no warning
nCRC = nCRC << 1; //Long to Integer warning.
its this line that seems to be causing the issue with Converting type [Long] to [INTEGER]
m_crc16c = g_pCRC16CcittTable[((m_crc16c >> 8) ^ crcString16c)+1] ^ (m_crc16c << 8);
This is actually documented as a CRC16-CITT checksum as well...
This seems to be compiling and producing a result I was looking for, although it seem to be inverted as I'm looking for $2C09 and getting $92C
little endian vs big endian I would expect...
Hello amx world,
Does anyone has a working example / function how to build CRC16-x25?
This is an example that I should calculate.
$00,$00,$03,$00,$12,$6c,$a5,$00,$00,$31,$31,$31,$31,$31,$31,$31,$31,$00 CRC low - CRC high ($D6,$2C)
Thanx.
http://www.mcgougan.se/universal_crc/
http://www.repairfaq.org/filipg/LINK/F_crc_v31.html
I realize that this a massive thread revival. How could this function be revised to calculate an 8 bit CRC?
Thank you!