Tuesday, August 19, 2008
Source Code RSA UnitEnfForm
unit EncForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls,Registry,strutils, ExtCtrls, Menus, ComCtrls, Buttons, ToolWin;
type
Tmain1 = class(TForm)
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
MainMenu1: TMainMenu;
File1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
Exit2: TMenuItem;
Option1: TMenuItem;
N1: TMenuItem;
ControlBar1: TControlBar;
ToolBar1: TToolBar;
BitBtn6: TBitBtn;
BitBtn5: TBitBtn;
BitBtn7: TBitBtn;
BitBtn8: TBitBtn;
ToolBar2: TToolBar;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
StatusBar1: TStatusBar;
Splitter1: TSplitter;
Memo1: TMemo;
Memo2: TMemo;
procedure cq(Sender: TObject; var CanClose: Boolean);
procedure kd(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure Option1Click(Sender: TObject);
procedure md(Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X,
Y: Integer);
procedure crt(Sender: TObject);
procedure SH(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn8Click(Sender: TObject);
procedure BitBtn7Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure Exit2Click(Sender: TObject);
procedure About1Click(Sender: TObject);
procedure Encodedfl(Sender: TObject);
procedure BtnLoadEncodedClick(Sender: TObject);
procedure BtnLoadPlainClick(Sender: TObject);
procedure enc(j,k,b:pchar);
procedure denc(j,k,b:pchar); private
procedure ShowHint(Sender: TObject);
procedure updt();
{ Private declarations }
public
{ Public declarations }
end;
var
main1: Tmain1;
reg:tregistry;
implementation
{$R *.DFM}
uses
RSA, Unit1, ABOUT,Unit2;
procedure Tmain1.Encodedfl(Sender: TObject);
var
EncStr: TRsaStream;
x:string;
j,k,y,c:pchar;
begin
reg:=tregistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion',false);
y:=pchar(reg.ReadString('Psnm'));
c:=pchar(inputbox('Identifikasi','Siapakah Anda ?',''));
if (strcomp(c,y)=0)then
begin
if SaveDialog1.Execute then
begin
x:=string(y);
EncStr := TRsaStream.Create(SaveDialog1.Filename, fmCreate);
try
j:=pchar(formatdatetime('dd/mm/yyyy hh:nn:ss:zzz',now));
Encstr.Write(x[1],length(x));
Memo1.Lines.SaveToStream (EncStr);
Encstr.Write(x[1],length(x));
k:= pchar(formatdatetime('hh:nn:ss:zzz ampm',now));
y:=pchar(SaveDialog1.Filename);
enc(j,k,y);
STATUSBAR1.Panels[2].Text:=savedialog1.FileName;
except
end;
EncStr.Free;
end;
end;
reg.Free;
c:=nil; j:=nil;k:=nil;
y:=nil; x:='';
end;
procedure Tmain1.BtnLoadEncodedClick(Sender: TObject);
var
EncStr: TRsaStream;
x:tstringstream;
j,k, y,c:pchar;
f,g,h:string;
begin
reg:=tregistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion',false);
y:=pchar(reg.ReadString('Psnm'));
c:=pchar(inputbox('Identifikasi','Siapakah Anda ?',''));
if (strcomp(c,y)=0)then
begin
x:=tstringstream.Create('');
if OpenDialog1.Execute then
begin
j:= pchar(formatdatetime('dd/mm/yyyy hh:nn:ss:zzz',now));
EncStr := TRsaStream.Create(OpenDialog1.FileName, fmOpenRead);
x.CopyFrom(encstr,encstr.Size);
k:=pchar(formatdatetime('hh:nn:ss:zzz ampm',now));
y:=pchar(opendialog1.filename);
denc(j,k,y);
try
f:=pchar(x.DataString);
g:=AnsiRightstr(f,length(c));
h:=AnsiLeftStr(f,length(c));
if (strcomp(pchar(g),pchar(h))=0) then
if (strcomp(c,pchar(h))=0) then
begin
f:=ansimidstr(f,(length(c)+1),(length(f)-length(string(c))-length(string(c))));
memo2.Lines.Text:=string(f);
STATUSBAR1.Panels[0].Text:=opendialog1.FileName;
end;
except
end;
EncStr.Free;x.Free;
end;
end;
c:=nil; j:=nil;k:=nil;
y:=nil; f:='';g:='';h:='';
reg.Free;
end;
procedure Tmain1.cq(Sender: TObject; var CanClose: Boolean);
begin
canclose:=false;
main2.Close;
end;
procedure Tmain1.crt(Sender: TObject);
begin
application.OnHint:=showhint;
end;
procedure Tmain1.Exit2Click(Sender: TObject);
begin
main2.Close;
end;
procedure Tmain1.kd(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
updt();
end;
procedure Tmain1.md(Sender: TObject; Button: TMouseButton; Shift:TShiftState;
X, Y: Integer);
begin
updt();
end;
procedure Tmain1.Option1Click(Sender: TObject);
begin
main3.ShowModal;
end;
procedure Tmain1.SH(Sender: TObject);
begin
if (paramcount>0)and fileexists(paramstr(1)) then
begin
memo1.Lines.LoadFromFile(paramstr(1));
STATUSBAR1.Panels[0].Text:=paramstr(1);
end
else
begin
STATUSBAR1.Panels[0].Text:='bikin baru';
end;
STATUSBAR1.Panels[3].Text:=datetostr(date);
end;
procedure Tmain1.About1Click(Sender: TObject);
begin
aboutbox.showmodal;
end;
procedure Tmain1.BitBtn4Click(Sender: TObject);
begin
if SaveDialog1.Execute then
begin
try
Memo2.Lines.SaveToFile(savedialog1.FileName);
STATUSBAR1.Panels[2].Text:=savedialog1.FileName;
except
end;
end;
end;
procedure Tmain1.BitBtn5Click(Sender: TObject);
begin
STATUSBAR1.Panels[0].Text:='bikin baru';
memo1.Clear;
memo2.Clear;
end;
procedure Tmain1.BitBtn6Click(Sender: TObject);
begin
memo1.CopyToClipboard;
end;
procedure Tmain1.BitBtn7Click(Sender: TObject);
begin
memo1.CutToClipboard;
end;
procedure Tmain1.BitBtn8Click(Sender: TObject);
begin
memo1.PasteFromClipboard;
end;
procedure Tmain1.BtnLoadPlainClick(Sender: TObject);
begin
if OpenDialog1.Execute then
Memo1.Lines.LoadFromFile (
OpenDialog1.FileName);
STATUSBAR1.Panels[0].Text:=opendialog1.FileName;
end;
procedure TMain1.ShowHint(Sender: TObject);
begin
if Length(Application.Hint) > 0 then
begin
StatusBar1.SimplePanel := True;
StatusBar1.SimpleText := Application.Hint;
end
else StatusBar1.SimplePanel := False;
end;
procedure TMain1.updt();
var
x,y:integer;
begin
x:=sendmessage(memo1.Handle,EM_LINEFROMCHAR,memo1.SelStart,0);
y:=sendmessage(memo1.Handle,EM_LINEINDEX,x,0);
statusbar1.Panels[1].Text:='Line : '+inttostr(x+1)':'+inttostr(memo1.SelStart-y+1);
end;
procedure tmain1.enc(j,k,b:pchar);
var
flnm:string;
logg: textfile;
begin
flnm:=changefileext(application.title,'.enc');
assignFile(logg,flnm);
if (fileexists(flnm)) then
append(logg)
else
begin
rewrite(logg);
writeln(logg,'encrypt');
writeln(logg,'KU[7,187]');
end;
try
writeln(logg,b+' '+j+' - '+k);
finally
closefile(logg);
end;
j:=nil;
k:=nil;
b:=nil;
end;
procedure tmain1.denc(j,k,b:pchar);
var
flnm:string;
logg: textfile;
begin
flnm:=changefileext(application.Title,'.dec');
assignFile(logg,flnm);
if (fileexists(flnm)) then
append(logg)
else
begin
rewrite(logg);
writeln(logg,'decrypt');
end;
try
writeln(logg,b+' '+j+' - '+k);
finally
closefile(logg);
end;
j:=nil;
k:=nil;
b:=nil;
end;
end.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment
sabar ya, komentar anda akan kami moderasi terlebih dahulu. laporkan kepada kami apabila ada post yang masih berbentuk kiri ke kanan. nuhun