CRC32

A CRC is a number which is supposed to change accordingly to the string its computed upon. So it can be used to detect if the user made changes to a chosen subset of the fields of a document.

When saving the document, just join the text values of the fields in an ordered manner, then get the CRC of that string and store it as a new field value. When checking the document for changes to those fields, make the string again and get its CRC. If the saved CRC and the one just computed are equal, then you should be reasonably sure that those field values have not changed, but if the CRC does change, then you can be completely sure that those field have changed as well!

A CRC32 class comes with the java.util.zip package, and LS2J can be used to access and use it.

Here is the code for a Java library, name it CRC32 Java

import java.util.zip.CRC32;

public class StringCRC32 {

    public static String StringCRC32 ( String s )
    {
        byte[] b = s.getBytes();

        CRC32 crc = new CRC32();

        for ( int i=0; i<b.length; i++ )
        {
            crc.update( b[i] );
        }

        return Long.toString( crc.getValue() );
    }

}

And here is a LS2J wrapper, just for making it simpler to use in LotusScript. It’s a LotusScript library and you should name it CRC32

'CRC32:

Option Public
Option Declare

Use "CRC32 Java"
Uselsx "*javacon"

Function StringCRC32( aString As String ) As String
    Dim jSession As JavaSession
    Set jSession = New JavaSession
    Dim jClass As JavaClass
    Set jClass = jSession.GetClass( "StringCRC32" )
    StringCRC32 = jClass.StringCRC32( aString )
End Function

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.