Board index » delphi » HELP: File handling and encryption problems!

HELP: File handling and encryption problems!

Hello All,
I'm in urgent help so first off I would just like to say any help
would be greatly appreciated.
I basically need a program (or to be more precise a procedure) that
will do the following in as simple a way as possible:
1 - Ask for an input file (Plain text or encrypted text file)
2 - Ask where the output file should be saved.
3 - Takes the input file, encryptes it using xor and then saves the it
as a text file in the given place.
That is all!
May sound simple to some of you but I have really been having problems
with it.
Any help is greatly appreciated and will not go un-thanked.
If anyone also has any source code that they could maybe send me to
deal with this problem this would be absolutely amazing. If so please
use my private email address at:    sazz...@-REMOVE-hotmail.com
Thank you all so very much,
Sarah xx
 

Re:HELP: File handling and encryption problems!


Re:HELP: File handling and encryption problems!


[not posted to bpb - i can't post to this ng]

hi sarah,

"Sarah" <sazz...@-REMOVE-hotmail.com> schrieb im Newsbeitrag
news:3ac8dbc5.2838638@news.freeserve.net...

Quote
> Hello All,
> I'm in urgent help so first off I would just like to say any help
> would be greatly appreciated.
> I basically need a program (or to be more precise a procedure) that
> will do the following in as simple a way as possible:
> 1 - Ask for an input file (Plain text or encrypted text file)
> 2 - Ask where the output file should be saved.
> 3 - Takes the input file, encryptes it using xor and then saves the it
> as a text file in the given place.
> That is all!
> May sound simple to some of you but I have really been having problems
> with it.
> Any help is greatly appreciated and will not go un-thanked.
> If anyone also has any source code that they could maybe send me to
> deal with this problem this would be absolutely amazing. If so please
> use my private email address at:    sazz...@-REMOVE-hotmail.com
> Thank you all so very much,
> Sarah xx

first of all, pm is not the idea of the usenet - others might be
interested in your question too.

do not use textfiles to do the job. by using xor you might get special
characters like lf,ff,cr,bs ... in the encoded file, which have a extra
meaning in textfiles.

use blockread, blockwrite instead.

something like this (quick&dirty - not tested)

function codeFile(var fIn, fOut: file; pw: string) : boolean;
var
   b: array[0..1023] of byte;
   bs, bp, pp: word;
begin
  codefile := false;
  if pw='' then exit;
  reset(fIn,1);
  if ioresult<>0 then exit;
  rewrite(fout,1);
  if ioresult<>0 then
    begin close(fIn); exit end;
  pp:=1;
  repeat
    blockread(fIn,b,1024,bs);
    for bp:=0 to bs to
    begin
      b[i]:=b[i] xor ord(pw[pp]);
      if pp>=length(pw) then pp:=1 else inc(pp)
    end;
    blockwrite(fOut,b,bs,bs)
  until bs<>1024;
  close(fIn);
  close(fOut);
  codeFile := true
end;

your mainprogramm should ask for password and filenames and assign them.

hth
jochen

Other Threads