unit  crypt;  
 
interface  
USES  
       Classes;  
const  
         C1  =  52845;  
         C2  =  22719;  
 
function  Encrypt(  S:  String;  Key:  Word):  String;  
function  Decrypt(  S:  String;  Key:  Word):  String;  
 
implementation  
 
function  Encrypt(  S:  String;  Key:  Word):  String;  
var  
     I:  Integer;  
     j:  Integer;  
begin  
 Result  :=  S;  
 for  I  :=  1  to  Length(S)  do  
 begin  
   Result[I]  :=  char(byte(S[I])  xor  (Key  shr  8));  
   Key  :=  (byte(Result[I])  +  Key)  *  C1  +  C2;  
 end;  
 s:=Result;  
 Result:='';  
 for  i:=1  to  length(s)  do  
 begin  
   j:=Integer(s[i]);  
   Result:=Result  +  Char(65+(j  div  26))+Char(65+(j  mod  26));  
 end;  
end;  
 
function  Decrypt(  S:  String;  Key:  Word):  String;  
var  
     I:  Integer;  
     j:  Integer;  
begin  
 result:='';  
 for  i:=1  to  (length(s)  div  2)  do  
 begin  
   j:=(Integer(s[2*i-1])-65)*26;  
   j:=j+(Integer(s[2*i])-65);  
   result:=result  +  Char(j);  
 end;  
 s:=result;  
 for  I  :=  1  to  Length(S)  do  
 begin  
   Result[I]  :=  char(byte(S[I])  xor  (Key  shr  8));  
   Key  :=  (byte(S[I])  +  Key)  *  C1  +  C2;  
 end;  
end;  
 
end.  
加密中文都ok了,就是解密有点问题。public  static  string  EncryptLittle(string  s,  UInt16  key)  
               {  
                       StringBuilder  sb  =  new  StringBuilder();  
                       string  result  =  "";  
                       int  p  =  0;  
                       byte[]  bt  =  Encoding.Default.GetBytes(s);  
                       for  (int  i  =  0;  i  <bt.Length;  i++)  
                       {  
                               sb.Append((char)(bt[i]  ^  (key  >>  8)));  
                               key  =  (UInt16)(((byte)sb[i]  +  key)  *  Var1  +  Var2);  
 
                       }  
                       for  (int  i  =  0;  i  <  sb.Length;  i++)  
                       {  
                               p  =  (int)sb[i];  
                               result  =  result  +  (char)(65  +  (p  /  26))  +  (char)(65  +  (p  %  26));  
                       }  
                       return  result;  
               }  
                 
             public  static  string  DecryptLittle(string  s,  UInt16  key)  
               {  
                       string  result  =  "";  
                       int  p  =  0;  
                       for  (int  i  =  0;  i  <  s.Length  /  2;  i++)  
                       {  
                               p  =  ((int)(s[2  *  i])  -  65)  *  26;  
                               p  =  p  +  (int)(s[2  *  i  +  1])  -  65;  
                               result  =  result  +  (char)p;  
                       }  
                       byte[]  bt  =  Encoding.Default.GetBytes(result);  
                       byte[]  bt2  =  new  byte[bt.Length];  
                       for  (int  i  =  0;  i  <  bt.Length;  i++)  
                       {  
                               bt2[i]  =  (byte)(bt[i]  ^  (key  >>  8));  
                               //byte  a  =  bt2[i];  
                               key  =  (UInt16)((bt[i]  +  key)  *  Var1  +  Var2);  
                       }  
                       return  Encoding.Default.GetString(bt2);  
               }