home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
554
/
JUIN
/
ENDECODE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-10-07
|
2KB
|
67 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 334 of 374
From : Bernie Pallek 1:247/128.0 29 May 93 19:38
To : Bernie Wilt
Subj : Menu Program!
────────────────────────────────────────────────────────────────────────────────
BW> I am needing to write a menu program that will allow a user
BW> (offline - nonBBS to view selected text files. I'd like for the
BW> text files to be encrypted, s BW>that they may only be viewed within
BW> the program.
BW>~Bernie Wilt~
Hey, cool first name! :^)
Of the trillions of encryption methods, one of the simplest is XOR.
Example:
~~~~~~~ }
PROGRAM EncodeDecode;
USES Crt, Dos;
CONST
Key = #254; { the "key" to the encypt/decrypt alogirthm }
VAR
ch : Char; { just a char for reading keys }
message : String; { a message to be encrypted }
cryptFile : Text; { this don't *have* to be global }
{ but it's easier this way, 'cuz }
{ you can use them anywhere... }
PROCEDURE WriteEncrpytedFile;
VAR
i : Integer;
BEGIN
Rewrite(cryptFile);
FOR i := 1 TO Length(message) DO BEGIN
Write(cryptFile, Chr(Ord(message[i]) XOR Key));
{ if the above line is confusing, quote it to me }
{ and I'll explain it in detail }
END;
Close(cryptFile);
END;
PROCEDURE ReadEncyptedFile;
VAR
i : Integer;
c : Char;
BEGIN
Reset(cryptFile);
REPEAT
Read(cryptFile, c);
Write(Chr(Ord(c) XOR Key));
UNTIL Eof(cryptFile);
WriteLn;
END:
BEGIN
ClrScr;
Assign(cryptFile, 'CRYPTED.DAT');
message := 'You cannot read this message without decrypting it!');
WriteEncryptedFile;
ReadEncryptedFile;
WriteLn; Write('Press any key...'); ch := ReadKey; WriteLn;
END.