求一对字符串加密解密最理想的有源码控件。(200分)

  • 主题发起人 主题发起人 cnkk
  • 开始时间 开始时间
MD5也叫加密算法???
MD5,sha1之类的叫做散列算法,你用来加密,如何恢复???
加密算法比较简单的可以找一些比如DES算法。
 
有一个DES加密单元非常的好, 比使用控件还方便安全
 
to 郭玉梁:谢谢能给我一个么? treemanwww@163.com
 
直接用一种加密算法(公式转换)比用控件更好,另外好象没有"最"好的加密算法
安全与方便之间找一个平衡点即可
 
有现成的控件,自己再修改一下。
 
To 郭玉梁:
  给兄弟我也发一个。
 
to:悲酥清风
你现在在哪,过得可否,有空小叙,留下信箱
 
可以用下面的算法
我覺得几好
不象有些算法
對有些字符串可以
反過來解密就不行了!

unit uEncryption;
interface
Function EncryptionEngine(Src:String;
Key:String;
Encrypt : Boolean):string;

implementation
Function EncryptionEngine(Src:String;
Key:String;
Encrypt : Boolean):string;
var
idx :integer;
KeyLen :Integer;
KeyPos :Integer;
offset :Integer;
dest :string;
SrcPos :Integer;
SrcAsc :Integer;
TmpSrcAsc :Integer;
Range :Integer;
begin
KeyLen:=Length(Key);
if KeyLen = 0 then
key:='Tom Lee';
KeyPos:=0;
SrcPos:=0;
SrcAsc:=0;
Range:=256;
if Encrypt then
begin
Randomize;
offset:=Random(Range);
dest:=format('%1.2x',[offset]);
for SrcPos := 1 to Length(Src)do
begin
SrcAsc:=(Ord(Src[SrcPos]) + offset) MOD 255;
if KeyPos < KeyLen then
KeyPos:= KeyPos + 1 else
KeyPos:=1;
SrcAsc:= SrcAsc xor Ord(Key[KeyPos]);
dest:=dest + format('%1.2x',[SrcAsc]);
offset:=SrcAsc;
end;
end
else
begin
offset:=StrToInt('$'+ copy(src,1,2));
SrcPos:=3;
repeat
SrcAsc:=StrToInt('$'+ copy(src,SrcPos,2));
if KeyPos < KeyLen then
KeyPos := KeyPos + 1 else
KeyPos := 1;
TmpSrcAsc := SrcAsc xor Ord(Key[KeyPos]);
if TmpSrcAsc <= offset then
TmpSrcAsc := 255 + TmpSrcAsc - offset
else
TmpSrcAsc := TmpSrcAsc - offset;
dest := dest + chr(TmpSrcAsc);
offset:=srcAsc;
SrcPos:=SrcPos + 2;
until SrcPos >= Length(Src);
end;
Result:=Dest;
end;

end.
 
我有DES,BlowFish,RC4,RC5,IDEA,CryptoApi For D6的控件
 
但是加密之后就不是:0-9,a-z,A-Z了
 
to gaisy
给我给我
catbrother@163.net
 
该控件修改一下即可在D6下用了。
 
unit uEncrypt;

interface
function Decrypt(const S: AnsiString;
Key: Word): AnsiString;
function Encrypt(const S: AnsiString;
Key: Word): AnsiString;

implementation
const
C1 = 52845;
C2 = 22719;

function Decode(const S: AnsiString): AnsiString;
const
Map: array[Char] of Byte = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0);
var
I: LongInt;
begin

case Length(S) of
2:
begin

I := Map[S[1]] + (Map[S[2]] shl 6);
SetLength(Result, 1);
Move(I, Result[1], Length(Result))
end;

3:
begin

I := Map[S[1]] + (Map[S[2]] shl 6) + (Map[S[3]] shl 12);
SetLength(Result, 2);
Move(I, Result[1], Length(Result))
end;

4:
begin

I := Map[S[1]] + (Map[S[2]] shl 6) + (Map[S[3]] shl 12) +
(Map[S[4]] shl 18);
SetLength(Result, 3);
Move(I, Result[1], Length(Result))
end
end
end;

function PreProcess(const S: AnsiString): AnsiString;
var
SS: AnsiString;
begin

SS := S;
Result := '';
while SS <> ''do

begin

Result := Result + Decode(Copy(SS, 1, 4));
Delete(SS, 1, 4)
end
end;

function InternalDecrypt(const S: AnsiString;
Key: Word): AnsiString;
var
I: Word;
Seed: Word;
begin

Result := S;
Seed := Key;
for I := 1 to Length(Result)do

begin

Result := Char(Byte(Result) xor (Seed shr 8));
Seed := (Byte(S) + Seed) * Word(C1) + Word(C2)
end
end;

function Decrypt(const S: AnsiString;
Key: Word): AnsiString;
begin

Result := InternalDecrypt(PreProcess(S), Key)
end;

function Encode(const S: AnsiString): AnsiString;
const
Map: array[0..63] of Char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
'abcdefghijklmnopqrstuvwxyz0123456789+/';
var
I: LongInt;
begin

I := 0;
Move(S[1], I, Length(S));
case Length(S) of
1:
Result := Map[I mod 64] + Map[(I shr 6) mod 64];
2:
Result := Map[I mod 64] + Map[(I shr 6) mod 64] +
Map[(I shr 12) mod 64];
3:
Result := Map[I mod 64] + Map[(I shr 6) mod 64] +
Map[(I shr 12) mod 64] + Map[(I shr 18) mod 64]
end
end;

function PostProcess(const S: AnsiString): AnsiString;
var
SS: AnsiString;
begin

SS := S;
Result := '';
while SS <> ''do

begin

Result := Result + Encode(Copy(SS, 1, 3));
Delete(SS, 1, 3)
end
end;

function InternalEncrypt(const S: AnsiString;
Key: Word): AnsiString;
var
I: Word;
Seed: Word;
begin

Result := S;
Seed := Key;
for I := 1 to Length(Result)do

begin

Result := Char(Byte(Result) xor (Seed shr 8));
Seed := (Byte(Result) + Seed) * Word(C1) + Word(C2)
end
end;

function Encrypt(const S: AnsiString;
Key: Word): AnsiString;
begin

Result := PostProcess(InternalEncrypt(S, Key))
end;

end.

{**************************************************************}
// Example:
{**************************************************************}
procedure TForm1.Button1Click(Sender: TObject);
const
my_key = 33189;
var
sEncrypted, sDecrypted :AnsiString;
begin

// Encrypt a string
sEncrypted := Encrypt('this is a sample text to encrypt...abcd 123 {}[]?=)=(',my_key);
// Show encrypted string
ShowMessage(sEncrypted);
// Decrypt the string
sDecrypted := Decrypt(sEncrypted,my_key);
// Show decrypted string
ShowMessage(sDecrypted);
end;


 
多人接受答案了。
 
to gaisy
麻烦给我一份谢谢wuzhenzhen@263.net
 
MD5是一种不可逆的算法,有人会吗?
请指点一二
mylhb2002@yahoo.com.cn
 
后退
顶部