reversible crypt?

I'm looking for a method of very simple encryption:

1) It must be able to encrypt a whole text file
2) The file must be decryptable using the same key
3) Security is not a big concern, mainly I just want the files to not be readable at first glance
3) I don't want to install any modules, .pm files, etc.

The reasoning behind this is that I have some files that I access with a script over the web, but the server they're stored on is a friend's, not mine.  I don't want him reading the files, but he's not the kind who would spend a lot of time trying to crack codes, so something very simple would do.  Any ideas?
oucherAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

samayCommented:
replace characters by certain others..
and put it back..
a->b
b->b
c->d
...

z->a

0
prakashk021799Commented:
Here's a simple rot13'er:

while (<>) {
    tr/[a-zA-Z]/[n-za-mN-ZA-M]/;
    print;
}

The same code will encrypt as well as decrypt the text. Of course, it handles only alphabetic characters. If you want it to handle numeric and other special characters, you need to extend the patterns above.
0
oucherAuthor Commented:
Thanks prakashk, that's the kind of thing I'm looking for.  For adding numeric and symbolic characters, is there some easy way to add or subtract do it using ASCII numbers?  Is there a Perl function that will convert a number to a char and vice versa?
0
prakashk021799Commented:
Char to numeric ASCII value:
    Use the 'ord' function. For example:

    print ord('A');   # prints 65

Numeric ASCII value to Char:
    Use the 'chr' function. For example:

    print chr(65);    # prints the character A

Actually, if you want to encode non-alphabetic characters, the code above needs to be changed. Also, the same code will not work for decoding it. Rot13 works for alphabetic characters for both encoding and decoding because there are 26 letters in the alphabet. So, if you rotate a character by 13 once and then repeat the rotation, you will get the same character. But when you add numeric characters the same thing does not hold. That's why the script in my previous comment does not encode non-alphabetic characters.

If you want encode all characters, you will need to use two separate scripts for encoding and decoding. In the following example, 13 is just an arbitrary number. You can choose any number in place of it.

encode script:

map {$rotmap{chr($_)} = chr(($_ + 13) % 256)} (0..255);
while (<>) {
    s/(.)/$rotmap{$1}/g;
    print;
}

decode script:

map {$unrotmap{chr($_)} = chr(($_ + 256 - 13) % 256)} (0..255);
while (<>) {
    s/(.)/$unrotmap{$1}/g;
    print;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oucherAuthor Commented:
Thanks a lot!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.