Tuesday, August 19, 2008
Source code RSA
unit RSA;
interface
uses
Classes;
type
TRSAStream = class (TFileStream)
private
FKey: Char;
public
constructor Create(const FileName: string; Mode: Word);
function Read(var Buffer; Count: Longint): Longint; override;
function Write(const Buffer; Count: Longint): Longint; override;
property Key: Char read FKey write FKey default 'A';
end;
implementation
constructor TRSAStream.Create(
const FileName: string; Mode: Word);
begin
inherited Create (FileName, Mode);
FKey := 'Z';
end;
function TRSAStream.Write(const Buffer;
Count: Longint): Longint;
var
pBuf, pEnc: PChar;
a,b,I,c,d, EncVal: Integer;
begin
GetMem (pEnc, Count);
try
pBuf := PChar (@Buffer);
for I := 0 to Count - 1 do
begin
a:=1;
b:=Ord (pBuf[I]) ;
for c := 0 to 2 do
begin
a:=a*b;
end;
a:=a mod 187;
B-32
c:= (a*a*b*a) mod 187;
d:= (a*a*a*a) mod 187;
EncVal := (c*d*b) mod 187;
pEnc [I] := Chr (EncVal);
end;
Result := inherited Write (pEnc^, Count);
finally
end;
FreeMem (pEnc, Count);
end;
function TRSAStream.Read(var Buffer; Count: Longint): Longint;
var
pBuf, pEnc: PChar;
a,b,c, I, CountRead, EncVal: Integer;
begin
GetMem (pEnc, Count);
try
CountRead := inherited Read (pEnc^, Count);
pBuf := PChar (@Buffer);
for I := 0 to CountRead - 1 do
begin
a:=1;
B-33
b:=Ord (pEnc[I]) ;
for c := 0 to 2 do
begin
a:=a*b;
end;
a:=a mod 187;
EncVal := ( a*a*b ) mod 187;
pBuf [I] := Chr (EncVal);
end;
finally
FreeMem (pEnc, Count);
end;
Result := CountRead;
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