¹®ÀÚ¿À» ¾ÏÈ£·Î ¸¸µé°í À̸¦ ȯ°æÆÄÀÏÀÎ INIÆÄÀÏ¿¡ ÀúÀåÇÑ ÈÄ ³ªÁß¿¡
ºÒ·¯¿À´Â °æ¿ì°¡ ÀÖÀ»°Ì´Ï´Ù
¾ÏÈ£¾È¿¡ ASCII Á¦¾î¹®ÀÚ°¡ Æ÷ÇԵǾî ÀÖ´Ù¸é(CR/LF µîµî)
ÅØ½ºÆ® ÆÄÀÏÀÎ INIÆÄÀÏ¿¡ À̸¦ ÀúÀåÇϸé Á¤È®ÇÏÁö ¾ÊÀº ¾ÏÈ£°¡
µÉ ¼ö ÀÖ½À´Ï´Ù(Àß ¾Ë·ÁÁø Leap FTP °¡ ±×·¸´õ±º¿ä)
±×·¡¼ ¾ÏÈ£¸¦ ´Ù½Ã ASCII ¼ýÀÚ·Î º¯È¯ÇÏ¿© ó¸®ÇÏ´Â ·çƾÀ»
Æ÷ÇÔÇß½À´Ï´Ù
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, StdCtrls, IniFiles;
type
TForm1 = class(TForm)
E_Name: TEdit;
E_Age: TEdit;
E_Password: TEdit;
CB_Married: TCheckBox;
SB_SaveINI: TSpeedButton;
SB_LoadINI: TSpeedButton;
procedure SB_SaveINIClick(Sender: TObject);
procedure SB_LoadINIClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function Encrypt(const S: String; Key: Word): String;
function Decrypt(const S: String; Key: Word): String;
end;
const
C1 = 52845; // ±âÁØÅ°1
C2 = 22719; // ±âÁØÅ°2
MY_KEY = 12345; // »ç¿ëÀÚŰ
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.Encrypt(const S: String; Key: Word): String;
var
i: Integer;
sEncrypt, rEncrypt: String;
rChar: Char;
begin
sEncrypt := ''; // ¾ÏÈ£ÈµÈ ÀÌÁø ¹®ÀÚ¿
if S = '' then
begin
Encrypt := '';
System.Exit;
end;
for i := 1 to Length(S) do
begin
sEncrypt := sEncrypt + char(byte(S[i]) xor (Key shr 8));
Key := (byte(sEncrypt[i]) + Key) * C1 + C2;
end;
rEncrypt := ''; // ¾ÏÈ£ÈµÈ ÀÌÁø ¹®ÀÚ¿À» ASCII ¼ýÀÚ·Î º¯°æ
for i := 1 to Length(sEncrypt) do
begin
rChar := sEncrypt[i];
rEncrypt := rEncrypt + format('%.3d', [Ord(rChar)]); // Çѹ®ÀÚ´ç 3ÀÚ¸®¾¿
end;
Result := rEncrypt;
end;
function TForm1.Decrypt(const S: String; Key: Word): String;
var
i: Integer;
sDecrypt, rDecrypt, temp: String;
begin
rDecrypt := '';
if S = '' then
begin
Decrypt := '';
System.Exit;
end;
i := 1;
repeat
temp := Copy(S, i, 3); // Çѹ®ÀÚ´ç 3ÀÚ¸® ¼ýÀÚ·Î ÀúÀåµÇ¾î ÀÖ´Ù
rDecrypt := rDecrypt + Chr(StrToIntDef(temp, 0)); // ASCII°ªÀ» ±¸ÇÑ´Ù
i := i + 3;
until i > Length(S);
sDecrypt := '';
for i := 1 to Length(rDecrypt) do
begin
sDecrypt := sDecrypt + char(byte(rDecrypt[i]) xor (Key shr 8));
Key := (byte(rDecrypt[i]) + Key) * C1 + C2;
end;
Result := sDecrypt;
end;
// ȯ°æÆÄÀÏ¿¡ ÀúÀå
procedure TForm1.SB_SaveINIClick(Sender: TObject);
var
IniFile: TIniFile;
begin
IniFile := TIniFile.Create('TEST.INI');
try
IniFile.WriteString('PERSON', 'À̸§', E_Name.Text);
IniFile.WriteInteger('PERSON', '³ªÀÌ', StrToIntDef(E_Age.Text,0));
IniFile.WriteBool('PERSON', '°áÈ¥¿©ºÎ', CB_Married.Checked);
IniFile.WriteString('PERSON', 'ºñ¹Ð¹øÈ£',Encrypt(E_Password.Text, MY_KEY));
finally
IniFile.Free;
end;
end;
// ȯ°æÆÄÀÏ¿¡¼ ºÒ·¯¿À±â
procedure TForm1.SB_LoadINIClick(Sender: TObject);
var
IniFile: TIniFile;
begin
IniFile := TIniFile.Create('TEST.INI');
try
E_Name.Text := IniFile.ReadString('PERSON', 'À̸§', '');
E_Age.Text := IntToStr(IniFile.ReadInteger('PERSON', '³ªÀÌ', 0));
CB_Married.Checked := IniFile.ReadBool('PERSON', '°áÈ¥¿©ºÎ', False);
E_Password.Text := Decrypt(IniFile.ReadString('PERSON', 'ºñ¹Ð¹øÈ£', ''), MY_KEY);
finally
IniFile.Free;
end;
end;
end.
|
|