1. encryption bug

Bryan Watts <mr_bungle at COMPUSERVE.COM> wrote
>I have recently gotten into data encryption algorithms, and just to
>see, I have developed a *very* basic one, implemented into
>the program at the end of this letter.  I can get a sentence
>encrypted and decrypted fine, and I can also encrypt a file
>as well.  My problem is that when I try to decrypt the file,
>sometimes the marker that shows which bit to switch in
>the character ("ch" in the "decrypt_file" procedure)
>sometimes reads in a very strange value, and causes a
>subscript error.  It happens randomly, sometimes not at all,
>and it has me completely baffled.  I think this would be a
>very cool program, and useful too, if I could get it to run!!
>Any help as to what may be causing this weird error would
>be greatly appreciated!!  Thanks a lot.

in procedure encrypt_file() you are using 2 file handles on the
same file, reading one byte and writing one or two bytes.

in procedure decrypt_file() you are using 2 file handles on the
same file, reading one or two bytes and writing one byte.

The approach will work when the file is small and will always fit
into the file buffers (read buffer and write buffer), it will
also work on a file of any size if you always read one byte and
always wrote 1 byte.

Imagine what happens when the write buffer gets full and is
written to disk (remember the write is ahead of the read in the
encrypt_file() procedure) and then sometime later the read
buffer gets updated from the disk.  You're now reading in
encrypted bytes.

I suggest that when changing a file's length, you use 2 files and
delete the first one when finished.

Matthew McNamara                          _
mat at iconz.co.nz                         o( )
The Internet Company of New Zealand    /  /\

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu