home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!elroy.jpl.nasa.gov!usc!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!mksol!mksol!mavmav
- From: mavmav@mksol.dseg.ti.com (michael a vincze)
- Subject: Re: Scramble text files
- Message-ID: <1993Jan5.185410.3773@mksol.dseg.ti.com>
- Sender: mavmav@mksol (michael a vincze)
- Nntp-Posting-Host: localhost
- Organization: Texas Instruments
- References: <726193861.AA01015@contrast.wlink.nl> <1993Jan5.082329.13550@ncsu.edu>
- Date: Tue, 5 Jan 1993 18:54:10 GMT
- Lines: 72
-
- In article <726193861.AA01015@contrast.wlink.nl> berend@contrast.wlink.nl
- (Berend de Boer) writes:
- |>
- |> Can anyone point me to some code that will scramble a text
- |> file? It could something that woudl do it on the fly (my
- |> program is creating the text to be appended to said file),
- |> or something I can churn the text file through later on.
- |> This doesn't hafta be fancy (DES etc. would be overkill,) I
- |> only need to keep the average user from using a text editor
- |> to view/modify this file.
-
- Each character in a text file (or any DOS file for that matter) is represented
- by a single byte. Therefore swapping low and high bytes would not work, unless
- you are talking about swapping adjacent characters that could easily be decoded
- by the user (just like pig Latin.) Swapping low and high order nibbles (4
- bits) would work. Also xor-ing with the file name would not work since the
- user may change the file name. Also a file name is comprised of several bytes,
- whereas a character of only one, unless you are talking about xor-ing a
- number of bytes with the file name. But then you have to keep track of
- string lengths.
-
- A solution I would like to propose is to add an incremental offset to each
- character. The offset would start with 0 and increment to 255, then wrap-
- around back to 0. The first character would recieve the first offset, the
- second character the second offset, etc. Here is some psuedo code:
-
- var I;Byte C: Byte;
- var InFile, OutFile: Binary;
-
- /* Encrypt */
- begin
- I := 0;
- Open_Infile;
- Open_OutFile;
- while not End_of_File (InFile) do
- begin
- Read (InFile, C);
- Inc (C, I);
- Inc (I);
- Write (OutFile, C);
- end;
- end;
-
- /* Decrpyt */
- begin
- I := 0;
- while not End_of_File (InFile) do
- begin
- Read (InFile, C);
- Dec (C, I);
- Dec (I);
- Write (OutFile, C);
- end;
- end;
-
- Of course there are gaps in the psuedo code, but I believe you can fill them
- in. Furhter I am assuming that a Byte type variable wraps (ie: 255+1 = 0, and
- 0-1 = 255.) I do not have my Pascal compiler in front of me so I can not
- verify this. If this is not the case then change Inc (C, I); Inc (I); to:
-
- if C+I > 255 then C := C+I-256 else Inc (C, I);
- if I = 255 then I := 0 else Inc (I);
-
- and change Dec (C, I); Dec (I); to:
-
- if C-I < 0 then C := C-I+256 else Dec (C, I);
- if I = 0 then I := 255 else Dec (I);
-
- Get in touch with me if you any other questions or comments.
-
- Michael Vincze
- mav@asd470.dseg.ti.com
-