再举个例子,可能有点土 :)
function encode(License:string):string;
var str,sNum:string
number:dword
byte,byte1:array[1..4]of dword;
inChar:array[1..3]of char;
begin
str:=license;
delete(str,1,1);
delete(str,2,1);
delete(str,3,1);
delete(str,6,1);
number:=strtoint64(str);
number:=not number;
number:=number xor $1972154980;
byte[1]:=(number and $0ff000000) shr 24;
byte[2]:=(number and $0ff0000) shr 16;
byte[3]:=(number and $0ff00) shr 8;
byte[4]:=(number and $0ff);
byte1[1]:=((byte[1]and $0c0)+(byte[2]and $0c0)shr 2)+((byte[3]and $0c0)shr 4)+((byte[4]and $0c0)shr 6);
byte1[2]:=((byte[1]and $30)shl 2)+(byte[2]and $30)+((byte[3]and $30)shr 2)+((byte[4]and $30)shr 4);
byte1[3]:=((byte[1]and $0c)shl 4)+((byte[2]and $0c)shl 2)+(byte[3]and $0c)+((byte[4]and $0c)shr 2);
byte1[4]:=((byte[1]and $03)shl 6)+((byte[2]and $03)shl 4)+((byte[3]and $03)shl 2)+(byte[4]and $03);
number:=((byte1[1])shl 24)+((byte1[2])shl 16)
+((byte1[3])shl 8)+(byte1[4]);
byte[1]:=((number and $0ff000000)shr 24);//右移24位
byte[2]:=((number and $0ff0000)shr 16);
byte[3]:=((number and $0ff00)shr 8);
byte[4]:=(number and $0ff);
byte[1]:=(((byte[1] and $f0))shr 4)+(((byte[1] and $0f))shl 4);
byte[2]:=(((byte[2] and $f0))shr 4)+(((byte[2] and $0f))shl 4);
byte[3]:=(((byte[3] and $f0))shr 4)+(((byte[3] and $0f))shl 4);
byte[4]:=(((byte[4] and $f0))shr 4)+(((byte[4] and $0f))shl 4);
number:=((byte[2])shl 24)+((byte[1])shl 16)
+((byte[4])shl 8)+(byte[3]);
sNum:=inttostr(Number);
inChar[1]:=char(((integer(sNum[1])+integer(sNum[2]))mod 5)+integer('a'));
inChar[2]:=char(((integer(sNum[3])+integer(sNum[4]))mod 5)+integer('a'));
inChar[3]:=char(((integer(sNum[5])+integer(sNum[6]))mod 5)+integer('a'));
insert(inChar[1],sNum,1);
insert(inChar[2],sNum,5);
insert(inChar[3],sNum,9);
result:=sNum;
end;