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.
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.
解决方案 »
- C#实现获取共享文件夹权限
- 为什么同样是去掉空字符,换个方法就不能输出了呢?
- 大哥大虾好~请问Container.DataItem的问题
- 如何让textBox只能输入数值(比如123、-123、1.23、-1.23),非法字符给出提示。
- 发送EMAIL
- C#新手问题-相对路径-进度条
- 如何使用as关键字
- 问个问题...各位都用c#做什么开发呀????我是因为课社觉得c#比c++简单才学的..不想学了以后用不上,谈谈c#有神么前途把...
- 如何关闭系统后台的进程?请思归等高手做答!如果有会的朋友,也可帮小弟一下!
- 如何把这样的日期"Sun, 18 Jan 2015 23:21:56 +0800"变换为"2015/1/18 15:21:56"
- 有没有有关提取当前计算机使用状态的函数?
- 为什么信誉分会被乱扣啊?
楼上两位不是想只是转换一下for,if等语句吧。估计是嫌分少,没办法了,只有90大洋,全都拿出去了,想+分都不行了,哪位高手仗义下阿,小弟我急用!!!
{
/// <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;
}
}
}编译过去了,不过没测过,你自己试一下吧
不过有错误,请帮忙再看看
使用cl_encrypt()编码正确
而使用
cl_decrypt进行解码时出错(在delphi中解码则完全正确)。在asp.net里面的错误信息为
Input string was not in a correct format
还请这位大哥再帮忙看看,哪里不对了,谢谢!