Board index » delphi » How do i save textfiles crypted?

How do i save textfiles crypted?

Quote
James Lee (sl...@io.wl.k12.in.us) wrote:

: You could use some very basic XOR encryption.  What you do is before you
: write a character to a file, use an eXclusiveOR on it.  Like so:

: { for text files, binary is similar }
: for i := 1 to Length(MyString) do
:    Write(MyFile,Char(Ord(Mystring[i]) xor $FF));

Let's hope that everybody who is reading this
knows that such a encryption is *TRIVIAL* to crack
even if the potential intruder does not know
exactly how it was done.

For a slightly better version, please have a look at
http://www.brain.uni-freiburg.de/~klaus/pascal/source
One unit is missing there, but it should
be sufficient to get the idea how it works.

Klaus
--
Klaus Hartnegg, Institut fuer Biophysik, Hansa-Strasse 9a, D-79104 Freiburg
Tel +49 761 203 9516, Fax 9540, e-mail: hartn...@uni-freiburg.de

 

Re:How do i save textfiles crypted?


"Jeroen Verhoeven, the HyperMan" <hy...@il.ft.hse.nl> wrote:

Quote
>You could try to use PGP which can be found on most ftp sites
>Jeroen Verhoeven
>=>mb...@hi.ft.hse.nl<=
>=>hy...@il.ft.hse.nl<=
>=>ej...@dds.nl<=
>On 12 Dec 1995, aaa wrote:
>> Hi..
>> I want to save some texts in crypted form in a file. It doesnt even have
>> to be really crypted, but just in a non-text form , so it cant be read by
>> text editors.. Ive tried to save it with array of chars, records, array of
>> integers with the chars in ascii numbers. but it wont work, the letters appear
>> no matter how i save it.. I now wonder , if someone could help me.
>> Im not familiar with encoding/crypting, maybe you could give me a quick
>> lesson.A pascal program would be great to show what i should do..

>> My other question: How do i save both integers and chars and booleans etc..
>> in ONE file. If i do it with records they will be written in a prechosen
>> order, what if I dont want that, and I want to save space?

>> Im not so familiar with turbo pascal, and its the only thing i have right now,
>> i should get a book..I will, but what should i do when i want to use pointers
>> (i.e. ^) to see the next record ?

>> Thank you for your time! bye!

The easiest way i know is to use a XOR encryption tenchnique.
You are using a text file so i would comment you to encrypt the
strings before you write them to the file. What you have to do is to
take a random character with which you XOR every char in the file.

EXAMPLE :

CONST
  CharKey = 'A';

PROCEDURE Crypt( VAR CryptString : string );
VAR
  i : Integer;
BEGIN
  for i := 1 to Length( CryptString ) do
    CryptString[i] := CryptString[i] XOR CharKey;
END;

VAR
  TestString : string;
  F : Text;
BEGIN
  TestString := 'This is encrypted!';
  Crypt( TestString );
  Open( F, 'TEST.CRP' );
  WriteLn( F, TestString );
  Close( F );
{Now you've made a file named 'TEST.CRP' with a non-readable text
  If you want to decrypt the text just put the string another time in

  the procedure Crypt }
  Open( F, 'TEST.CRP' );
  ReadLn( F, TestString );
  Crypt( TestString );
  Close( F );
  WriteLn( TestString );
END.

The XOR crypting works like this:

Take a number :   10110111 (binary, could represent a char/string)
And a key           :   01110100
                                  -------------- XOR
XOR them               11000011
and the result is something completly different.
Now, YOU know the key so when you take the
encrypted number  : 11000011
and your key            : 01110100
                                       --------------- XOR
                                       10110111
you'll get your original number back!
Without the key, you wont get to know what's in your file.

   If you want more information,
      Paul Kuijer
      p.h.j.kui...@student.utwente.nl

Go to page: [1] [2]

Other Threads