📄 modify.~pas
字号:
unit modify;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TFormModify = class(TForm)
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
BTNClose: TBitBtn;
BTNEnter: TBitBtn;
CmbUser: TComboBox;
private
{ Private declarations }
procedure LoadData ; // 从文件载入
procedure SaveData; // 保存到文件
public
{ Public declarations }
end;
//function encypt(input:string): string;
//procedure EncryptFile(var InS,OutS: Strings; Key: LongWord);
//procedure DecryptFile(var InS,OutS: Strings; Key: LongWord);
function DecryptStr(const S: string; Key: Word): string;
function EncryptStr(const S: string; Key: Word): string;
var
FormModify: TFormModify;
implementation
{$R *.dfm}
{const keyword='j'; //关键字
function encypt(input: string): string;
var i:integer;
begin
for i:=0 to length(input) do
input[i]:=input xor keyword;
result:=input;
end; }
{
procedure EncryptFile(var InS,OutS:strings;Key:LongWord);
var
X:Integer;
C:Byte;
begin
FOR X := 0 TO length(Ins) - 1 DO
begin
C := InS(X);
C := (C xor (Key shr 8));
Key := (C + Key) * C1 + C2;
OutS(X) := C;
end;
end;
procedure DecryptFile(var InS,OutS:strings;Key:LongWord);
var
X:Integer;
C,O:Byte;
begin
FOR X:=0 TO MS.Size - 1 DO
begin
C := InS(X);
O:=C;
C:=(C xor (Key shr 8));
Key:=(O + Key) * C1 + C2;
OutS(X) := C;
end;
end; }
type
Tbm= record
Usename: String[8]; //用户名
Pass: String[10]; // 密码
end;
const
C1Key = 12674; // C1 = 52845;
C2Key = 35891; // C2 = 22719;
var
bm: Tbm;
FileHandle: Integer;
function DecryptStr(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) * C1Key + C2Key;
end;
end;
function EncryptStr(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) * C1Key + C2Key;
end;
end;
procedure TFormModify.SaveData; // 保存到文件
begin
FileHandle:=FileCreate('.\Data.dat');
with bm do begin
Usename := Edit2.Text ;
Pass := EncryptStr(edit3.text,123);
end;
FileWrite(FileHandle,bm,Sizeof(bm));
FileClose(fileHandle);
end;
procedure TFormModify.LoadData ; // 从文件载入
begin
FileHandle:=FileOpen('.\Data.dat',fmOpenread or fmShareDenyNone);
FileRead(FileHandle,bm,Sizeof(bm));
with Bm do begin
Edit2.Text:=Usename ;
edit3.Text:=DecryptStr(Pass,123);
end;
fileclose(fileHandle);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -