home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
554
/
JUILLET
/
CRYPT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-10-07
|
2KB
|
87 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 366 of 394
From : David Drzyzga 1:3612/220.0 04 Jul 93 18:23
To : All
Subj : Encryption
────────────────────────────────────────────────────────────────────────────────
Thaere hasn't been much on this subject for the last couple of weeks, but here
is an encryption/decryption scheme that would be very difficult to crack:}
{------------------------------------------------------------------------------
Original source code by David Drzyzga, FidoNet 1:3612/220, SysOp of
=>> CUTTER JOHN'S <<= (904) 932-1849 [HST]
07-04-1993
------------------------------------------------------------------------------}
program crypt;
uses
crt;
var
Index,
UserKey : longint;
NumRead,
NumWritten : word;
InFile,
OutFile : file;
InFileName,
OutFileName : string[79];
Buffer : array[1..51200] of char;
NumStr : string[10];
Ch : char;
Error : integer;
function crypt(ch:char):char;
var
UserKey_byte : byte;
begin
UserKey_byte := UserKey shr 24;
crypt := chr(ord(ch) xor ord(UserKey_byte));
UserKey := $63C5 * UserKey + $A561;
{The two constants above can be changed but must be prime #s}
end;
begin
clrscr;
write('Enter FileName to En/Decrypt: ');
readln(InFileName);
assign(InFile, InFileName);
{$I-} reset(InFile,1); {$I+}
if IOResult <> 0 then begin
writeln('Input file does not exist');
halt;
end;
write('Enter output fileName: ');
readln(OutFileName);
if InFileName = OutFileName then begin
writeln('Input file and output file must be different');
halt;
end;
assign(OutFile, OutFileName);
rewrite(OutFile, 1);
write('Enter a numeric encription key between 1 and 2-billion: ');
NumStr := '';
repeat
Ch := readkey;
if Ch in ['0'..'9'] then begin
write(Ch);
NumStr := NumStr + Ch;
end;
until (length(NumStr) = 10) or (Ch = #13);
val(NumStr,UserKey,Error);
writeln(#10#13'En/Decrypting file ...');
repeat
blockread(InFile, Buffer, sizeof(Buffer), NumRead);
for Index := 1 to NumRead do
Buffer[Index] := crypt(Buffer[Index]);
blockwrite(OutFile, Buffer, NumRead, NumWritten);
until (NumRead = 0) or (NumWritten <> NumRead);
close(InFile);
close(OutFile);
end.