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