TIP: Click on subject to list as thread! ANSI
echo: z3_pascal
to: Ben Grosman
from: Doug Brendish
date: 1996-03-31 22:36:00
subject: HELP!

BG> Hey there Everyone...
BG> Need some help please...
BG> gotta write  a program in Pascal...
BG> it either has to be a text based adventure game, or an 
BG> encryption/decryption
BG> program..
BG> I would prefer to do the encryption/decryption program...

Well, the simplest way would be to open two files, as files of (Type) byte,
one as the target encrypted file and the other the original file. Read the
original file one byte at a time and NOT it with it's own value and write
the NOT(ed) byte value to the new file. This is a VERY simple form of
encryption. A better way is to XOR encrypt. This way you need to define,
for the simplest way, one value to XOR each char value with. For more
security XOR the file with a password, which you will need to convert each
char to their ordinal value and in turn through the length of the PW XOR
the ORDinal of the char to the character you are encrypting or make a
checksum of the password and XOR each ORD(CH) with the checksum. There are
probably so may ways to encrypt it's not funny. Depends how inportant the
info.
Anyway here is a short example:(NO IO checking, thats for you to do.)

Program encrypt_file;
Uses DOS;
Var
   F1, F2:File of Byte;
   S: String;
   I,U,X:Byte;
Begin
 U:=0;
 X:=9; {For ease this is our password}
 Writeln('This file will be XOR encrypted with decimal: ',X);
 Writeln('Enter the file to encrypt');
 Readln(S);
 Assign(F1,S);
 Reset(F1); {This will be opened}
 Writeln('What will we call the encrypted file?');
 Readln(S);
 Assign(F2,S);
 Rewrite(F2);{This will create a new file or kill and create an existing file}
 For I := 0 to Filesize(F1) do 
{Read a byte from the source file, XOR and write to the other}
 Begin
  Read(F1,U);
  U:=U XOR X;
  Write(F2,U);
 End;
 Close(F1);
 Close(F2);
End.

This is knocked up on the fly, but should basically XOR each byte in the
file with 9 and write the result to another file. I have just come home
from a BBQ and a few beers so don't take it too seriously. It's an example.
There are better ways to encrypt, but if you can make numbers(Using ORD and
VAL) out of a password and use that as an XOR on a file of byte, then the
recipient can decypher it with the password you used to encrypt it with. It
basically works on the fact that any number(1) XORed with number(2) will be
the original number(1) if XORed with number (2) again. If you choose to use
NOTing then any number NOTed with it's self with be the original again
after NOTing again.
Gimme a yell if I can help more.

--- Msgedsq/2 3.10
* Origin: Tir na nOc 066 245944 -=Cead mile failte=- (3:626/667)
SEEN-BY: 633/267 270
@PATH: 626/667 660 711/401 808 50/99 635/544 727 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.