我有一个支持各种算法,请发一封信到[email protected],我收到后给你发过去
解决方案 »
- 关于时间比较
- 请问这样一个delphi 中query1 的sql 语句怎么样写????
- 请问高手 :如何得到文件大小与系统显示的大小一致?
- 请大家提供点思路(100分)
- 向各位老师请教delphi保存图片问题?
- 送你10分
- 关于FastReport的一个问题,快来帮帮忙!给你们高分!!!!!!!!!!!
- Group Policy Objects注册项下面的随机的guid值怎么获取?
- 通过ADO实现在SQLServer中创建超级用户???
- 关于加密解密?
- SOS:各位大侠,请问哪里可找到Delphi和C++ Builder等Borland软件的免费下载?谢了!
- 大家进来研究研究:D5跟D6的差距
作 者: pingguo (e网情深)
等 级:
信 誉 值: 100
所属论坛: Delphi
问题点数: 38
回复次数: 3
发表时间: 2002-1-5 14:53:32
如何实现对文本的加密和解密?
回复人: VSaber(☆浪人☆) ( ) 信誉:100 2002-1-5 14:56:26 得分:3
简单一点作异或处理吧
回复人: feismile() ( ) 信誉:100 2002-1-5 15:43:38 得分:5
我有加密和解密函数如下,希望你作一下参考:加密函数是vb写的,转换一下就可以了!!
'用户口令加密
Public Function PassWordCode(password As String) As StringDim il_bit, il_x, il_y, il_z, il_len, i As Long
Dim is_out As String
il_len = Len(password)
il_x = 0
il_y = 0
is_out = ""
For i = 1 To il_len
il_bit = AscW(Mid(password, i, 1)) 'W系列支持unicodeil_y = (il_bit * 13 Mod 256) + il_x
is_out = is_out & ChrW(Fix(il_y)) '取整 int和fix区别: fix修正负数
il_x = il_bit * 13 / 256
Next
is_out = is_out & ChrW(Fix(il_x))password = is_out
il_len = Len(password)
il_x = 0
il_y = 0
is_out = ""
For i = 1 To il_len
il_bit = AscW(Mid(password, i, 1))
'取前4位值
il_y = il_bit / 16 + 64
is_out = is_out & ChrW(Fix(il_y))
'取后4位值
il_y = (il_bit Mod 16) + 64
is_out = is_out & ChrW(Fix(il_y))
Next
PassWordCode = is_out
End Function解密函数如下:
function PassWordDeCode(password: string): string;
var
il_x, il_y, il_len, I, il_bit: Integer;
begin
Result := '';
for I := 1 to Length(password) div 2 do begin
il_bit := Ord(password[I * 2 - 1]);
il_y := (il_bit - 64) * 16;
il_y := il_y + Ord(password[I * 2 ]) - 64;
Result := Result + Chr(il_y);
end;
password := Result;
Result := '';
il_len := Length(password);
il_x := Ord(password[il_len]);
for i := (il_len - 1) downto 1 do begin
il_y := il_x * 256 + Ord(password[I]);
il_x := il_y mod 13;
Result := Chr(il_y div 13) + Result;
end;
end;
回复人: pdsinfo(新手) ( ) 信誉:100 2002-1-5 16:12:01 得分:30
//异或加密,看看这个单元吧
//复杂的,可以参考DES,RSA,AES...
unit EncryptIt;
interface
USES Classes;
const
C1 = 52845;
C2 = 22719;
function Encrypt(const S: String; Key: Word): String;
function Decrypt(const S: String; Key: Word): String;
procedure EncryptFile(INFName, OutFName : String; Key : Word);
procedure DecryptFile(INFName, OutFName : String; Key : Word);
implementationfunction Encrypt(const S: String; Key: Word): String;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(Result[I]) + Key) * C1 + C2;
end;
end;function Decrypt(const S: String; Key: Word): String;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S) do
begin
Result[I] := char(byte(S[I]) xor (Key shr 8));
Key := (byte(S[I]) + Key) * C1 + C2;
end;
end;
procedure EncryptFile(INFName, OutFName : String; Key : Word);
VAR
MS, SS : TMemoryStream;
X : Integer;
C : Byte;
begin
MS := TMemoryStream.Create;
SS := TMemoryStream.Create;
TRY
MS.LoadFromFile(INFName);
MS.Position := 0;
FOR X := 0 TO MS.Size - 1 DO
begin
MS.Read(C, 1);
C := (C xor (Key shr 8));
Key := (C + Key) * C1 + C2;
SS.Write(C,1);
end;
SS.SaveToFile(OutFName);
FINALLY
SS.Free;
MS.Free;
end;
end;procedure DecryptFile(INFName, OutFName : String; Key : Word);
VAR
MS, SS : TMemoryStream;
X : Integer;
C, O : Byte;
begin
MS := TMemoryStream.Create;
SS := TMemoryStream.Create;
TRY
MS.LoadFromFile(INFName);
MS.Position := 0;
FOR X := 0 TO MS.Size - 1 DO
begin
MS.Read(C, 1);
O := C;
C := (C xor (Key shr 8));
Key := (O + Key) * C1 + C2;
SS.Write(C,1);
end;
SS.SaveToFile(OutFName);
FINALLY
SS.Free;
MS.Free;
end;
end;end.
对字符串
for i:=1 to Length(s) do
s[i]:=Chr(Ord(s[i]) xor 1234);
对数字
i:=i xor 1234;
重复上述操作即为解密。
zswang(伴水)(需要充充电) :
function Encrypt(const S: String; Key: Word): String;
中的 s和key应该带什么值?