Linux Tips


[an error occurred while processing this directive]

No Title

[an error occurred while processing this directive]

Reference: Cisco: Internetworking Basics



While attempting to port several applications written on the Solaris platform to Linux, I needed to use the "crypt" program, 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! Thanks to Ben Okopnik for creating a small Perl utility that provides the functionality of the "crypt" program.

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 # screen. 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


#!/usr/bin/perl -w # Created by Ben Okopnik on Sat Sep 8 10:11:23 UTC 2001 $pass = shift or die "Usage: ", $0 =~ /([^\/]*$)/, " passwd < file\n"; undef $/; # Set "slurp mode" @file = split //, <>; # Make a 'character' array from file # Tweak the password itself to avoid "known text XOR" attack @pass = map{ $x = ord; $y = ( $x + 10 ) ** 2 % 256; $z = ( $x - 10 ) ** 2 % 256; chr ( $y ^ $z ) } split //, $pass; # Do The Right Thang! print chr( ord $file[$_] ^ ord $pass[$_ % scalar @pass] ) for 0 .. $#file

About the Author

Jeffrey Hunter is an Oracle Certified Professional, Java Development Certified Professional, Author, and an Oracle ACE. Jeff currently works as a Senior Database Administrator for The DBA Zone, Inc. located in Pittsburgh, Pennsylvania. His work includes advanced performance tuning, Java and PL/SQL programming, developing high availability solutions, capacity planning, database security, and physical / logical database design in a UNIX / Linux server environment. Jeff's other interests include mathematical encryption theory, tutoring advanced mathematics, programming language processors (compilers and interpreters) in Java and C, LDAP, writing web-based database administration tools, and of course Linux. He has been a Sr. Database Administrator and Software Engineer for over 20 years and maintains his own website site at: Jeff graduated from Stanislaus State University in Turlock, California, with a Bachelor's degree in Computer Science and Mathematics.

Copyright (c) 1998-2018 Jeffrey M. Hunter. All rights reserved.

All articles, scripts and material located at the Internet address of is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at

I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.

Last modified on
Sunday, 01-May-2011 01:02:53 EDT
Page Count: 31322