Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Obscure data

by sweetblood (Prior)
on Nov 24, 2003 at 14:55 UTC ( [id://309545]=perlquestion: print w/replies, xml ) Need Help??

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

I'm working on a script that will manage a control file that up untill now has been manually edited. I want to be able to in some simple way obscure the data in the control file to prevent users from trying to edit it manually. Any trivial encryption should be fine, I don't expect that anyone would bother to try to "crack" this file. I just don't want them to be tempted to use vi on it. The control file contains ":" delimited records that have alpha, numeric and alpha/numeric fields. I'd prefer to "encrypt" by record as opposed to encrypting/decrypting the whole file at once. If anyone has ideas on what methods to use to obscure these data, I'd be greatful.

Thanks!

Replies are listed 'Best First'.
Re: Obscure data
by Corion (Patriarch) on Nov 24, 2003 at 14:57 UTC

    The easiest way would be to use Compress::Zlib or gzip, and simply save your config file compressed, and decompress it for modification.

    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
      gzip and it's cousins seem too trivial to undo -- the point (I think) is to make it too difficult to unobscure.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

Re: Obscure data
by edoc (Chaplain) on Nov 24, 2003 at 15:27 UTC
      This is perhaps, just what I'm looking for. Since my data are in a hash of annonymous hashes, this let's me save the whole structure as is. Although it does not completely obscure the data, it's ruffed up enough that no faint-hearted user would be inclined to try and muck with it.
      Nice suggestion++. Great Solution!
Re: Obscure data
by BrowserUk (Patriarch) on Nov 24, 2003 at 15:00 UTC
Re: Obscure data
by Ninthwave (Chaplain) on Nov 24, 2003 at 15:03 UTC

    Why not change the permissions on the file? Give everyone read access, but create a user that script will use that is the only user with write access to the file.

    "No matter where you go, there you are." BB
Re: Obscure data
by dragonchild (Archbishop) on Nov 24, 2003 at 16:16 UTC
    Personally, I like the idea of Acme::Bleach'ing your config files. :-)

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    ... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Obscure data
by Abigail-II (Bishop) on Nov 24, 2003 at 15:33 UTC
    What about rot13?

    Abigail

      Abigail-II is right. If your only goal is to make the data unintelligible to the layperson to discourage manual editing of a configuration file, there's probably no need to go to great lengths to encrypt it. And if that's the case, ROT-13 is a good solution.

      ROT-13 (from what I recall) was a technique first made ubiquitously common on Usenet, particularly when consciencious adults posting "racey" text-based material (sex stories, etc.) to public Usenet groups (possibly viewed by children) applied a ROT-13 to their message before posting it so that innocent eyes wouldn't just happen across an F-word or a story about some X rated experience.

      Many newsreaders still have a ROT-13 decode option built in. But the point was that you had to be able to recognize that it's ROT-13'ed, and you had to consciously apply the decoding.

      Chances are your end users aren't going to bother with applying a ROT-13 decoding just on the off chance of finding that suddenly they're able to edit your configuration file.

      Here's how it works. Take any letter of the english alphabet, and rotate rotate it 13 characters. The Perl way to do this is with transliteration, and I belive that Abigail-II already posted an example of that later in this thread.

      If you're afraid that ROT-13 isn't secure enough, do this: Add a checksum to the end of the ROT-13'ed file. If someone tampers with the file they'll have to also adjust the checksum. But the point is that ROT-13 isn't secure, it's just a pain in the butt, which will probably either confuse or discourage would-be tinkerers. Kinda like car door locks. Anyone can still get in, but why bother when the car parked next to yours forgot to lock up altogether?


      Dave


      "If I had my life to live over again, I'd be a plumber." -- Albert Einstein
      I'm not sure what rot13 is but it sounds deliciously morbid.(g) Can you elaborate? I've done no encryption previously and have a very minimal degree of knowledge in the area.I have however learned from being here to take your suggestions seriously.

      Thanks!

        It's dumb. It's something like
        perl -le'$_=shift;s/(.)/chr( 13 + ord $1)/ge;print' abcdef nopqrs --- [from jargon] --- rot13 /rot ther'teen/ n.,v. [Usenet: from `rotate alphabet 13 places'] The simple Caesar-cypher encryption that replaces each English lett +er with the one 13 places forward or back along the alphabet, so that +"The butler did it!" becomes "Gur ohgyre qvq vg!" Most Usenet news readi +ng and posting programs include a rot13 feature. It is used to enclose + the text in a sealed wrapper that the reader must choose to open -- e.g +., for posting things that might offend some readers, or {spoiler}s. A major advantage of rot13 over rot(N) for other N is that it is self-inverse, so the same code can be used for encoding and decodin +g. See also {spoiler space}, which has partly displaced rot13 since non-Unix-based newsreaders became common.

        rot13 == add 13 to the value of a character.

        I've only ever used it on alpha type data streams, but I assume you could do something similar on numbers as well. Simple rot13 key gen below. The value in the top row becomes the value in the bottom row, and vice versa

        $f = 'a'; for ( 0 .. 25 ) { print "$f "; print "\n" if $_ == 12; $f++; } print "\n";

        use perl;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-18 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found