interfaceuses
  SysUtils;const
  StartKey = 956;   {Start default key}
  MultKey   = 58645; {Mult default key}
  AddKey   = 28564; {Add default key}function cl_encrypt(s:string):string;
function cl_decrypt(s:string):string;//function Encrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
//function Decrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;implementation{$R-}
{$Q-}
{*******************************************************
 * Standard Encryption algorithm - Copied from Borland *
 *******************************************************}
function Encrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
var
  I : Byte;
begin
  Result := '';
  for I := 1 to Length(InString) do
  begin
    Result := Result + CHAR(Byte(InString[I]) xor (StartKey shr 8));
    StartKey := (Byte(Result[I]) + StartKey) * MultKey + AddKey;
  end;
end;
{*******************************************************
 * Standard Decryption algorithm - Copied from Borland *
 *******************************************************}
function Decrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
var
  I : Byte;
begin
  Result := '';
  for I := 1 to Length(InString) do
  begin
    Result := Result + CHAR(Byte(InString[I]) xor (StartKey shr 8));
    StartKey := (Byte(InString[I]) + StartKey) * MultKey + AddKey;
  end;
end;
{$R+}
{$Q+}{Coded by cloudy}
Function cl_intto0str(int1:integer; len:integer):string;
var
   i,j:integer;
begin
     if length(inttostr(int1))>=len then
        result:=inttostr(int1)
     else
        begin
             result:='';
             i:=len-length(inttostr(int1));
             for j:=1 to i do result:=result+'0';
             result:=result+inttostr(int1);
        end;
end;{Coded by cloudy}
function cl_chartobytestr(s:string):string;
var
   i:byte;
begin
     result:='';
     for i:=1 to length(s) do
         result:=result+cl_intto0str(byte(s[i]),3);
end;function cl_bytetocharstr(s:string):string;
var
   i:integer;
begin
     i:=1;
     result:='';
     if (length(s) mod 3)=0 then
        while i<length(s) do
        begin
            result:=result+char(strtoint(copy(s,i,3)));
            i:=i+3;
        end;
end;{Coded by cloudy}
function cl_encrypt(s:string):string;
var
   years, months, days, hours, mins, secs, msec:word;
   cl_StartKey, cl_MultKey, cl_AddKey: longint;begin
     decodedate(now, years, months, days);
     decodetime(now, hours, mins, secs, msec);
     cl_StartKey:=msec;
     if cl_StartKey<256 then cl_StartKey:=cl_StartKey+256;
     cl_Multkey:=((years-1900)*12+months)*30+days+cl_StartKey*10+cl_StartKey;
     cl_AddKey:=(23*hours+mins)*60+secs+cl_StartKey*10+cl_StartKey;
     result:=cl_chartobytestr(Encrypt(cl_intto0str(cl_StartKey,3),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(cl_intto0str(cl_Multkey,5),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(cl_intto0str(cl_Addkey,5),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(s,cl_StartKey,cl_MultKey,cl_AddKey));
end;{Coded by cloudy}
function cl_decrypt(s:string):string;
var
   cl_StartKey, cl_Multkey, cl_AddKey:longint;
begin
   cl_StartKey:=strtoint(decrypt(cl_bytetocharstr(copy(s, 1, 9)),StartKey,MultKey,AddKey));
   cl_MultKey:=strtoint(decrypt(cl_bytetocharstr(copy(s, 10, 15)),StartKey,MultKey,AddKey));
   cl_AddKey:=strtoint(decrypt(cl_bytetocharstr(copy(s, 25, 15)),StartKey,MultKey,AddKey));
   result:=decrypt(cl_bytetocharstr(copy(s, 40, length(s)-39)),cl_StartKey,cl_MultKey,cl_AddKey);
end;
end.

解决方案 »

  1.   

    晕,也就7个函数,其中5个函数代码量超少,最后两个函数也只是稍微有点点长,
    楼上两位不是想只是转换一下for,if等语句吧。估计是嫌分少,没办法了,只有90大洋,全都拿出去了,想+分都不行了,哪位高手仗义下阿,小弟我急用!!!
      

  2.   

    多谢jhtchina(好多技术需要学习) ,大好人啊!!!
      

  3.   

    using System;namespace WindowsApplication1
    {
    /// <summary>
    /// D2CS の概要の説明です。
    /// </summary>
    public class D2CS
    { private const int  StartKey = 956; //{Start default key}
    private const int MultKey = 58645; //{Mult default key}
    private const int AddKey = 28564;  //{Add default key}
    public D2CS()
    {
    } // 
    // TODO: コンストラクタ ロジックをここに追加してください。
    //
    //{*******************************************************
    // * Standard Encryption algorithm - Copied from Borland *
    // *******************************************************}
    //function Encrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
    //var
    //  I : Byte;
    //begin
    //  Result := '';
    //  for I := 1 to Length(InString) do
    //  begin
    //    Result := Result + CHAR(Byte(InString[I]) xor (StartKey shr 8));
    //    StartKey := (Byte(Result[I]) + StartKey) * MultKey + AddKey;
    //  end;
    //end;
    public static string Encrypt(string InString, int StartKey, int MultKey, int AddKey)
    {
    byte i = 0;
    string result = "";
    for (i = 0; i < InString.Length ; i++)
    {
    InString[i].ToString();
    result += (char)((byte)(InString[i]) ^ (StartKey >> 8));
    StartKey = ((byte)result[i] + StartKey) * MultKey + AddKey;
    }
    return result;
    } //{*******************************************************
    // * Standard Decryption algorithm - Copied from Borland *
    // *******************************************************}
    //function Decrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string;
    //var
    //  I : Byte;
    //begin
    //  Result := '';
    //  for I := 1 to Length(InString) do
    //  begin
    //    Result := Result + CHAR(Byte(InString[I]) xor (StartKey shr 8));
    //    StartKey := (Byte(InString[I]) + StartKey) * MultKey + AddKey;
    //  end;
    //end; public static string Decrypt(string InString, int StartKey, int MultKey, int AddKey)
    {
    byte i = 0;
    string result = "";
    for (i = 0; i < InString.Length ; i++)
    {
    InString[i].ToString();
    result += (char)((byte)(InString[i]) ^ (StartKey >> 8));
    StartKey = ((byte)InString[i] + StartKey) * MultKey + AddKey;
    }
    return result;
    } //{Coded by cloudy}
    //Function cl_intto0str(int1:integer; len:integer):string;
    //var
    //   i,j:integer;
    //begin
    //     if length(inttostr(int1))>=len then
    //        result:=inttostr(int1)
    //     else
    //        begin
    //             result:='';
    //             i:=len-length(inttostr(int1));
    //             for j:=1 to i do result:=result+'0';
    //             result:=result+inttostr(int1);
    //        end;
    //end;

    private string cl_intto0str(int int1, int len)
    {
    int i,j = 0;
    string result = "";
    if (int1.ToString().Length > len)
    {
    result = Convert.ToString(int1);
    }
    else
    {
    i = len - int1.ToString().Length;
    for (j = 1 ; j <= i ; j++)
    result += "0";
    result += Convert.ToString(int1);
    }
    return result;
    } //{Coded by cloudy}
    //function cl_chartobytestr(s:string):string;
    //var
    //   i:byte;
    //begin
    //     result:='';
    //     for i:=1 to length(s) do
    //         result:=result+cl_intto0str(byte(s[i]),3);
    //end; private string cl_chartobytestr(string s)
    {
    byte i = 0;
    string result = "";
    for (i = 0; i < s.Length ; i++)
    result += cl_intto0str((byte)s[i], 3);
    return result;
    } //function cl_bytetocharstr(s:string):string;
    //var
    //   i:integer;
    //begin
    //     i:=1;
    //     result:='';
    //     if (length(s) mod 3)=0 then
    //        while i<length(s) do
    //        begin
    //            result:=result+char(strtoint(copy(s,i,3)));
    //            i:=i+3;
    //        end;
    //end; private string cl_bytetocharstr(string s)
    {
    int i = 0;
    string result = "";
    if (s.Length % 3 == 0)
    {
    while (i < s.Length)
    {
    result += (char)(Convert.ToInt32(s.Substring(i,3)));
    i+=3;
    }
    }
    return result;
    }
    //{Coded by cloudy}
    //function cl_encrypt(s:string):string;
    //var
    //   years, months, days, hours, mins, secs, msec:word;
    //   cl_StartKey, cl_MultKey, cl_AddKey: longint;
    //
    //begin
    //     decodedate(now, years, months, days);
    //     decodetime(now, hours, mins, secs, msec);
    //     cl_StartKey:=msec;
    //     if cl_StartKey<256 then cl_StartKey:=cl_StartKey+256;
    //     cl_Multkey:=((years-1900)*12+months)*30+days+cl_StartKey*10+cl_StartKey;
    //     cl_AddKey:=(23*hours+mins)*60+secs+cl_StartKey*10+cl_StartKey;
    //     result:=cl_chartobytestr(Encrypt(cl_intto0str(cl_StartKey,3),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(cl_intto0str(cl_Multkey,5),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(cl_intto0str(cl_Addkey,5),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(s,cl_StartKey,cl_MultKey,cl_AddKey));
    //end; private string cl_encrypt(string s)
    {
    int years, months, days, hours, mins, secs, msec = 0;
    int cl_StartKey, cl_MultKey, cl_AddKey = 0;
    string result = "";
    years = DateTime.Now.Year;
    months = DateTime.Now.Month;
    days = DateTime.Now.Day;
    hours = DateTime.Now.Hour;
    mins = DateTime.Now.Minute;
    secs = DateTime.Now.Second;
    msec = DateTime.Now.Millisecond;
    cl_StartKey = msec;
    if (cl_StartKey < 256)
    {
    cl_StartKey +=cl_StartKey;
    }
    cl_MultKey = ((years-1900)*12+months)*30+days+cl_StartKey*10+cl_StartKey;
    cl_AddKey = (23*hours+mins)*60+secs+cl_StartKey*10+cl_StartKey;
    result = cl_chartobytestr(Encrypt(cl_intto0str(cl_StartKey,3),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(cl_intto0str(cl_MultKey,5),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(cl_intto0str(cl_AddKey,5),StartKey,MultKey,AddKey))+cl_chartobytestr(Encrypt(s,cl_StartKey,cl_MultKey,cl_AddKey));
    return result;
    } //{Coded by cloudy}
    //function cl_decrypt(s:string):string;
    //var
    //   cl_StartKey, cl_Multkey, cl_AddKey:longint;
    //begin
    //   cl_StartKey:=strtoint(decrypt(cl_bytetocharstr(copy(s, 1, 9)),StartKey,MultKey,AddKey));
    //   cl_MultKey:=strtoint(decrypt(cl_bytetocharstr(copy(s, 10, 15)),StartKey,MultKey,AddKey));
    //   cl_AddKey:=strtoint(decrypt(cl_bytetocharstr(copy(s, 25, 15)),StartKey,MultKey,AddKey));
    //   result:=decrypt(cl_bytetocharstr(copy(s, 40, length(s)-39)),cl_StartKey,cl_MultKey,cl_AddKey);
    //end; private string cl_decrypt(string s)
    {
    int cl_StartKey, cl_MultKey, cl_AddKey = 0;
    string result = "";
    cl_StartKey = Convert.ToInt32(Decrypt(cl_bytetocharstr(s.Substring(0,9)),StartKey,MultKey,AddKey));
    cl_MultKey = Convert.ToInt32(Decrypt(cl_bytetocharstr(s.Substring(9,15)),StartKey,MultKey,AddKey));
    cl_AddKey = Convert.ToInt32(Decrypt(cl_bytetocharstr(s.Substring(24,15)),StartKey,MultKey,AddKey));
    result = Decrypt(cl_bytetocharstr(s.Substring(39,s.Length-39)),cl_StartKey,cl_MultKey,cl_AddKey);
    return result;
    }
    }
    }编译过去了,不过没测过,你自己试一下吧
      

  4.   

    谢谢 rcom10002(KNIGHTRCOM) ,
    不过有错误,请帮忙再看看
    使用cl_encrypt()编码正确
    而使用
    cl_decrypt进行解码时出错(在delphi中解码则完全正确)。在asp.net里面的错误信息为
    Input string was not in a correct format
    还请这位大哥再帮忙看看,哪里不对了,谢谢!