to: foreveryday007(有無數種方法可以浪費一天的時間…但是…) 一堆方法在那儿呢,能否告知?
反向操作? 如果正向操作是:(ord(字符)+3)*2 那反向操作就是:(ord(字符)/2)-3
//加密一个字符串 function XorEncode(const Key, Source: string): String; var I: Integer; C: Byte; begin Result := ''; for I := 1 to Length(Source) do begin //和关键字产生一个随机数 if Length(Key) > 0 then C := Byte(Key[1 + ((I - 1) mod Length(Key))]) xor Byte(Source[I]) else C := Byte(Source[I]); //产生一个二位的十六进制代码 Result := Result + AnsiLowerCase(IntToHex(C, 2)); end; end;//解密一个字符串 function XorDecode(const Key, Source: string): String; var I: Integer; C: Char; begin Result := ''; for I := 0 to Length(Source) div 2 - 1 do begin C := Chr(StrToIntDef('$' + Copy(Source, (I * 2) + 1, 2), Ord(' '))); if Length(Key) > 0 then C := Chr(Byte(Key[1 + (I mod Length(Key))]) xor Byte(C)); Result := Result + C; end; end;
比如 type g_power = packed record ys : Smallint; gl : integer; end;//读 rocedure TForm2.Memo1Click(Sender: TObject); var FileN:string; TextFileVar: file; i,K,M,N:integer; j:SmallInt; c_power: array[0..15] of g_power; //文件数据结构 WgYear,WgMonth,WgDay:word; //要导入的日期 begin if Memo1.Items.Count>0 then begin try AssignFile(TextFileVar ,Memo1.Items.Strings[Memo1.ItemIndex]); Reset(TextFileVar, 1); M:=1; While not Eof(TextFileVar) Do Begin BlockRead(TextFileVar, j, SizeOf(j), i); BlockRead(TextFileVar, c_power, SizeOf(g_power)*16, i); For k:=1 to 16 do begin StringGrid1.Cells[K,M]:=inttostr(c_power[k-1].GL); end; M:=M+1; end; finally CloseFile(TextFileVar); end; end; end;//如果是写也一样的
2.再對此文本文件的每個字符加密。如(ord(字符)+3)*2
3.需要讀取時再反向操作
读取时怎么反向操作?
一堆方法在那儿呢,能否告知?
如果正向操作是:(ord(字符)+3)*2
那反向操作就是:(ord(字符)/2)-3
function XorEncode(const Key, Source: string): String;
var
I: Integer;
C: Byte;
begin
Result := '';
for I := 1 to Length(Source) do begin
//和关键字产生一个随机数
if Length(Key) > 0 then
C := Byte(Key[1 + ((I - 1) mod Length(Key))]) xor Byte(Source[I])
else
C := Byte(Source[I]);
//产生一个二位的十六进制代码
Result := Result + AnsiLowerCase(IntToHex(C, 2));
end;
end;//解密一个字符串
function XorDecode(const Key, Source: string): String;
var
I: Integer;
C: Char;
begin
Result := '';
for I := 0 to Length(Source) div 2 - 1 do begin
C := Chr(StrToIntDef('$' + Copy(Source, (I * 2) + 1, 2), Ord(' ')));
if Length(Key) > 0 then
C := Chr(Byte(Key[1 + (I mod Length(Key))]) xor Byte(C));
Result := Result + C;
end;
end;
XorEncode(EncodeKey, PasswordEdit.Text)
XorEncode(EncodeKey, PasswordEdit.Text)
const EncodeKey = '20030504';
type g_power = packed record
ys : Smallint;
gl : integer;
end;//读
rocedure TForm2.Memo1Click(Sender: TObject);
var FileN:string;
TextFileVar: file;
i,K,M,N:integer;
j:SmallInt;
c_power: array[0..15] of g_power; //文件数据结构
WgYear,WgMonth,WgDay:word; //要导入的日期
begin
if Memo1.Items.Count>0 then
begin
try
AssignFile(TextFileVar ,Memo1.Items.Strings[Memo1.ItemIndex]);
Reset(TextFileVar, 1);
M:=1;
While not Eof(TextFileVar) Do
Begin
BlockRead(TextFileVar, j, SizeOf(j), i);
BlockRead(TextFileVar, c_power, SizeOf(g_power)*16, i);
For k:=1 to 16 do
begin
StringGrid1.Cells[K,M]:=inttostr(c_power[k-1].GL);
end;
M:=M+1;
end;
finally
CloseFile(TextFileVar);
end;
end;
end;//如果是写也一样的