Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Text files and binary files

by Anonymous Monk
on Nov 28, 2003 at 08:30 UTC ( [id://310668]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
We have a web page that takes input from the users and feeds the content to a plain text file. The problem is that the file can be easily viewed and can be changed by prying eyes.
I need to change this file to a format, something like a binary, which is not easy to recognise and can only be read using scripts.
Is this possible? If so how will I be able to do the transformation?

Replies are listed 'Best First'.
Re: Text files and binary files
by Corion (Patriarch) on Nov 28, 2003 at 08:41 UTC

    There are some easy ways of hiding information from prying eyes :

    • Use rot13 transformation for each line of the file (A -> N, B -> O
    • Use compress to compress and decompress the file
    • Use MIME to encode the file as a Base64 encoded file
    Use of any of these mechanisms will need the following approach to using your file:
    1. read the file
    2. decode the data
    3. process the data
    4. encode the data
    5. rewrite the complete file

    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
Re: Text files and binary files
by davido (Cardinal) on Nov 28, 2003 at 08:34 UTC
    You can use pack and unpack to transform it into something unintelligible from an "average human" standpoint. With those tools, you could convert it to 0's and 1's if you wanted, or uuencoding, though most likely you would just pack it from text to 'binary' format, and unpack it later. For that matter, you could even ROT-13 it with tr/A-Za-z/N-ZA-Mn-za-m/;

    But that's not the ultimate in security. More like, simple obscurity. Don't put credit card numbers and missile launch codes into the file.


    Dave


    "If I had my life to live over again, I'd be a plumber." -- Albert Einstein
Re: Text files and binary files
by Anonymous Monk on Nov 28, 2003 at 08:59 UTC
    The problem is that the file can be easily viewed and can be changed by prying eyes.

    So stop that. Change the permissions on the file and move it out of the document root.

      Why on earth do you have a file - ANY FILE - where it can be seen? Move the file out of the document root, or any document area where it can be seen. Change the permissions so that only the script can read and write it. This is one of the cardinal rules of web site building - if there is the most remote possibilitty that someone can see or modify a file they inevitably will, and far sooner than you anticipate.

      jdtoronto

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://310668]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-19 06:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found