var glbTst: array of byte; //全局procedure StrToByteArry(); var str:string; i:integer; begin str:='C:\文件夹\553.bmp'; setLength(glbTst,length(str)); for i:=1 to length(str) do glbTst[i]:=byte(str[i]); end;procedure ByteArryToStr(); var str:string; i:integer; begin SetLength(str,length(glbTst));//设置字符串长度 for i:=1 to length(glbTst) do begin str[i]:=char(glbTst[i]); end; ShowMessage(str); end;
MD5还原不回来的,用DES就可以了。
随便一个简单的 Const C1 = 05888; C2 = 01958; kk = 12588; //c1,c2,kk为密钥Function Encrypt(S:string): string;//S为要加密的字符串 Var I, key: Integer; M: Byte; str: String; Begin key := kk; For I := 1 To Length(S) Do Begin M := byte(S[I]) Xor (Key Shr 4); Key := (M + Key) * C1 + C2; str := Format('%2x', [M]); If str[1] = ' ' Then str[1] := '0'; Result := Result + str; End; End;Function Decrypt(S:string):string;//解密 Var I, key: Integer; M: Byte; Begin key := kk; For I := 1 To Length(S) Div 2 Do Begin M := strToInt('x' + copy(s, I * 2 - 1, 2)); Result := Result + char(M Xor (Key Shr 4)); Key := (M + Key) * C1 + C2; End; End;
glbTst: array of byte; //全局procedure StrToByteArry();
var
str:string;
i:integer;
begin
str:='C:\文件夹\553.bmp';
setLength(glbTst,length(str));
for i:=1 to length(str) do
glbTst[i]:=byte(str[i]);
end;procedure ByteArryToStr();
var
str:string;
i:integer;
begin
SetLength(str,length(glbTst));//设置字符串长度
for i:=1 to length(glbTst) do
begin
str[i]:=char(glbTst[i]);
end;
ShowMessage(str);
end;
Const
C1 = 05888;
C2 = 01958;
kk = 12588; //c1,c2,kk为密钥Function Encrypt(S:string): string;//S为要加密的字符串
Var
I, key: Integer;
M: Byte;
str: String;
Begin
key := kk;
For I := 1 To Length(S) Do
Begin
M := byte(S[I]) Xor (Key Shr 4);
Key := (M + Key) * C1 + C2;
str := Format('%2x', [M]);
If str[1] = ' ' Then
str[1] := '0';
Result := Result + str;
End;
End;Function Decrypt(S:string):string;//解密
Var
I, key: Integer;
M: Byte;
Begin
key := kk;
For I := 1 To Length(S) Div 2 Do
Begin
M := strToInt('x' + copy(s, I * 2 - 1, 2));
Result := Result + char(M Xor (Key Shr 4));
Key := (M + Key) * C1 + C2;
End;
End;