Gossamer Forum
Home : General : Perl Programming :

Simple 'crypt' / 'decrypt'

Quote Reply
Simple 'crypt' / 'decrypt'
Hi, when users visit a certain section of my site the index.cgi script places a cookie called 'ref' with the referer as value (stripped and cleansed like 'www.gossamer-threads.com'). This a couple of pages later I can use this information when people fill-in a request information email.

Only, instead of having the complete referer visible in the cookie I would like something like 'gfhjfjkshahfjkash'. But not too complicated! Saw some 5/6 lines heavy crypt and decrypt function.

But I was more thinking of 'cba' instead of 'abc' or 'zyx' instead of 'abc'. (a one lines code Wink)

Last edited by:

cK: May 31, 2002, 10:55 AM
Quote Reply
Re: [cK] Simple 'crypt' / 'decrypt' In reply to
Code:
#!/usr/bin/perl

my $referer = 'www.foo.com';
my $crypt;
my $decrypt;

$crypt = join("\\", map { ord } (split //, $referer));
$decrypt = join("", map { chr } (split /\\/, $crypt));

print "Content-type: text/html\n\n";
print "$crypt => $decrypt";

Last edited by:

Paul: May 31, 2002, 11:39 AM
Quote Reply
Re: [Paul] Simple 'crypt' / 'decrypt' In reply to
Thanks, really! Wink

Note: Just wanted to write that the script needs a (very) small edit, but you already changed it!
Quote Reply
Re: [cK] Simple 'crypt' / 'decrypt' In reply to
Would anyone know the PHP version of this simple script? Would be VERY VERY handy!
Quote Reply
Re: [cK] Simple 'crypt' / 'decrypt' In reply to
Easy: Sly

Code:
<?php

$referer = 'www.foo.com';

$crypt = implode("-", array_map(ord, preg_split('//',$referer, -1, PREG_SPLIT_NO_EMPTY)));
$decrypt = implode("", array_map(chr, preg_split('/-/',$crypt, -1, PREG_SPLIT_NO_EMPTY)));

echo $crypt."=>".$decrypt;

?>

Only now I viewed my old code again, this 'crypt decrypt' snippet is very very simple. Does anyone know a better one? Temporary I'm using "128" and not "-" as a delimitor. It's only a cover-up Wink