|1 2 3 4 5 6 7 8|
There is no guarantee that your questions here will ever be answered. Readers at confidential sites must provide permission to publish. However, you can be published anonymously - just let us know!
From Ben Okopnik
Just a little while ago, I needed to use the "crypt" program, so well-known in other Unices, to encode a text file (for those of you unfamiliar with it, it encrypts the contents of a file using a password that you supply. A fairly useful little utility when you want just a bit of added security on a publicly-readable file.) Imagine my surprise when I found that Linux does not have one! Once again, it's Perl to the rescue.
This version follows the syntax of the original "crypt", although I'm certain that the algorithm is different. The encryption and the decryption are symmetric, meaning that the same syntax is used for both (with the obvious exception of the relevant filenames):
# This encrypts the contents of "mysecret.txt" using "iAMw0tIam" as the
# password and saves the results to "mysecret.encrypted".
crypt iAMw0tIam < mysecret.txt > mysecret.encrypted
# This prints out the decrypted contents of "mysecret.encrypted" to the
crypt iAMw0tIam < mysecret.encrypted
# This decrypts the contents of "mysecret.encrypted" and writes the results
# to "mysecret.decrypted".
crypt iAMw0tIam < mysecret.encrypted > mysecret.decrypted
Long passwords are preferable to short ones for better security; "crypt" accepts them without a problem, provided that any password containing spaces or other "weird characters" is quoted (preferably in single quotes).
crypt 'Praeterea, censeo Carthaginem esse delendam.' < file > file.enc
As always, bug reports, comments, and piles of diamonds are welcome.
See attached crypt.perl.txt
|1 2 3 4 5 6 7 8|