Blog信息 |
blog名称:注册会计师(注会)练习软件 日志总数:398 评论数量:116 留言数量:27 访问次数:3269756 建立时间:2005年6月6日 |

| |
[delpih编程]公司用字符串加密解密函数(delphi版)【转贴】 软件技术
吕向阳 发表于 2009/4/18 17:41:10 |
公司用字符串加密函数(delphi版)(2006-07-07 14:29:59) {字符串加密解密 2005.04.12 Wahnch Yeh}unit uEncrypt;interfaceusessysutils;constEncrypt_Const = $3412;function Encrypt(const S: String; Key: Word): String;function Decrypt(const S: String; Key: Word): String;implementationfunction TransChar(AChar: Char): Integer;beginif ((Achar>='0') and (Achar<='9')) thenresult := Ord(AChar) - Ord('0')elseResult := 10 + Ord(AChar) - Ord('A');end;function StrToHex(AStr: string): string;varI : Integer;beginResult := '';For I := 1 to Length(AStr) dobeginResult := Result + Format('%2x', [Byte(AStr[I])]);end;I := Pos(' ', Result);While I <> 0 dobeginResult[I] := '0';I := Pos(' ', Result);end;end;function HexToStr(AStr: string): string;varI : Integer;Charvalue: Word;beginResult := '';For I := 1 to Trunc(Length(Astr)/2) dobeginResult := Result + ' ';Charvalue := TransChar(AStr[2*I-1])*16 + TransChar(AStr[2*I]);Result[I] := Char(Charvalue);end;end;function Encrypt(const S: String; Key: Word): String;varI : Integer;beginResult := S;for I := 1 to Length(S) dobeginResult[I] := char(byte(S[I]) xor (Key shr 8));Key := (byte(Result[I]) + Key) * $C1 + $C2;if Result[I] = Chr(0) then Result[I] := S[I];end;Result := StrToHex(Result);end;function Decrypt(const S: String; Key: Word): String;varI: Integer;S1: string;beginS1 := HexToStr(S);Result := S1;for I := 1 to Length(S1) dobeginif char(byte(S1[I]) xor (Key shr 8)) = Chr(0) thenbeginResult[I] := S1[I];Key := (byte(Chr(0)) + Key) * $C1 + $C2; //±V¤Key的正取ば浴 endelse beginResult[I] := char(byte(S1[I]) xor (Key shr 8));Key := (byte(S1[I]) + Key) * $C1 + $C2;end;end;end;end. |
|
|