
rGeoffrey
User
Jun 7, 2001, 2:19 PM
Post #4 of 5
(739 views)
|
If you need to be able to undo the encryption you could do something like this...
my $string = "Four score and seven years ago..."; print $string, "\n"; $string =~ tr/a-zA-Z/n-za-mN-ZA-M/; print $string, "\n"; $string =~ tr/a-zA-Z/n-za-mN-ZA-M/; print $string, "\n"; This a a ROT13 encryption where every letter is rotated 13 positions in the alphabet. So the same method again will bring it back. But you are probably better off using a more complicated substitution, just make sure that all 26 letters are replaced with all 26 letters. If you just need to be able to verify that the password matches the encrypted one on file you can use crypt...
my $password = 'bedrock'; my $salt = 'qN'; #some 'random' two characters my $encrypted = crypt ($password, $salt); if ($encrypted eq crypt ($password, $encrypted)) { print "welcome back\n"; } else { print "your password does not match\n"; } crypt will use the "salt" to decide how to do the encryption and will take your password of upto 8 significant characters and return one of 13 characters where the first two are the salt. So then you just encrypt their guess of a password using the one on file as the salt. If that matches the one on file then they are who they say they are. If you need heavy duty security you should look into something stronger, but these two methods should at least force the bad guys to do a little thinking and not just walk in because you forgot to lock the door. -- Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?
|