Die folgenden Funktionen Verschlüsseln bzw. Entschlüsseln eine ID (ganze positive Zahl) als String mit folgenden Eigenschaften:
function EncodeId( aId ) ' Require( aId >= 0 ) dim magic, keyIndex, key9bit1, key9bit2, idPart, keyPart, magicPart, seed, magicCode magic = 331 ' 9 Bit Randomize keyIndex = CLng( Rnd() * 999 ) + 1 ' 1-999 if keyIndex >= 999 then keyIndex = 999 seed = Rnd() key9bit1 = CLng( Rnd(-keyIndex/1001) * 512 ) ' 0..511 = 9 Bit if key9bit1 >= 511 then key9bit1 = 511 key9bit2 = CLng( Rnd() * 512 ) ' 0..511 = 9 Bit if key9bit2 >= 511 then key9bit2 = 511 Rnd(-seed) idPart = CStr((aId xor key9bit1) + 123) ' min 3 digits magicCode = magic xor (aId and 511) magicPart = CStr((magicCode xor key9bit2) + 123) ' min 3 digits keyPart = Right( "000" & CStr(keyIndex), 3 ) ' 3 digits EncodeId = idPart & keyPart & magicPart end function function DecodeId( aCodeStr ) ' if aCodeStr represents no valid ID >= 0 then -1 is returned dim magic, codeLen, magicPart, keyPart, idPart, keyIndex, key9bit1, key9bit2, seed, id, magicCode magic = 331 ' 9 Bit DecodeId = -1 codeLen = Len(aCodeStr) if codeLen < 9 then exit function magicPart = Right( aCodeStr, 3 ) keyPart = Mid( aCodeStr, codeLen-5, 3 ) idPart = Left( aCodeStr, codeLen-6 ) if not IsNumeric(magicPart) or not IsNumeric(keyPart) or not IsNumeric(idPart) then exit function keyIndex = CLng(keyPart) seed = Rnd() key9bit1 = CLng( Rnd(-keyIndex/1001) * 512 ) ' 0..511 = 9 Bit if key9bit1 >= 511 then key9bit1 = 511 key9bit2 = CLng( Rnd() * 512 ) ' 0..511 = 9 Bit if key9bit2 >= 511 then key9bit2 = 511 Rnd(-seed) id = (CLng(idPart) - 123) xor key9bit1 magicCode = (CLng(magicPart) - 123) xor key9bit2 if (magicCode xor (id and 511)) <> magic then exit function DecodeId = id end function