<% '################################################## '# # '# Functions for creating and testing Index codes # '# # '################################################## '############################ ' return a char representing a number N in base 36 ' assumes n ranges 0..35 Function Base36Encode(n) If (n<10) Then Base36Encode=Chr(n+48) Else Base36Encode=Chr(n-10+65) End If End Function '############################ ' return a number 0..35 representing a digit C ' assumes c ranges 0..9A..Z Function Base36Decode(c) If (Asc(c)<=Asc("9")) Then Base36Decode=Asc(c)-48 Else Base36Decode=Asc(c)+10-65 End If End Function '############################ 'return a string encoding an integer N in base 36, with 3 check digits following 'possible range of n is 0 to about 1.6 million (36^4 in fact) Function IndexCode(n) Dim a,b,c,d,e,f,g,h a="D" b=Base36Encode((n \ (36*36*36)) mod (36)) ' \ is integer division c=Base36Encode((n \ (36*36)) mod (36)) d=Base36Encode((n \ 36) mod (36)) e=Base36Encode(n mod (36)) f=Base36Encode(((7*n+68)mod 117) mod (36)) g=Base36Encode((5*n) mod (36)) h=Base36Encode((Base36Decode(f)+Base36Decode(g)) mod (36) ) IndexCode=a&b&c&d&e&f&g&h End Function '############################ ' takes a string, and tests to see if it is a valid Index code Function ValidIndexCode(code) Dim a,b,c,d,e Dim N If Len(Code)<> 8 Then ValidIndexCode=False Else a=Mid(code,1,1) b=Mid(code,2,1) c=Mid(code,3,1) d=Mid(code,4,1) e=Mid(code,5,1) n=Base36Decode(b)*36*36*36 n=n+Base36Decode(c)*36*36 n=n+Base36Decode(d)*36 n=n+Base36Decode(e) ValidIndexCode=(IndexCode(n)=code) End If End Function Function IndexDecode(code) Dim a,b,c,d,e Dim N If Len(Code)<> 8 Then IndexDecode=0 Else a=Mid(code,1,1) b=Mid(code,2,1) c=Mid(code,3,1) d=Mid(code,4,1) e=Mid(code,5,1) n=Base36Decode(b)*36*36*36 n=n+Base36Decode(c)*36*36 n=n+Base36Decode(d)*36 n=n+Base36Decode(e) IndexDecode=n End If End Function %>