Mark G. Franz <[EMAIL PROTECTED]> wrote:
> Posted for a friend, this is his message;
>
> I need to encript my CGI form URL that is enerated thru a perl
> script "page1.cgi". The URL that the CGI script generates is
> like: "name=me&ph=1234"
>
> To enscript the above, one suggested me to use character shift
> to encode the above URL. a->c, b->d, p->r etc.. I tried this.
> But never thought it is so tough. I could write the 1st
> function, enc() that changes a->c, n->p, y->a..
>
> but when I try to write dec() that does the reverse,
> $var = "m"; $var--; does not work..
It seems a bit much to use the word "encrypt" for that.
Encryption is usually something more sophisticated. Maybe
"obfuscate" would be more appropriate.
In any case, the best way to do what you describe is the tr///
function, which allows you to do it in one line, like this:
$text =~ tr/a-zA-Z/c-zabC-ZAB/; # obfuscate
$text =~ tr/c-zabC-ZAB/a-zA-Z/; # unobfuscate
As for your problem with $var--, note that the documentation
(in perlop) says:
The auto-increment operator has a little extra builtin
magic to it. If you increment a variable that is numeric,
or that has ever been used in a numeric context, you get a
normal increment. If, however, the variable has been used
in only string contexts since it was set, and has a value
that is not the empty string and matches the pattern
/^[a-zA-Z]*[0-9]*\z/, the increment is done as a string,
preserving each character within its range, with carry:
print ++($foo = '99'); # prints '100'
print ++($foo = 'a0'); # prints 'a1'
print ++($foo = 'Az'); # prints 'Ba'
print ++($foo = 'zz'); # prints 'aaa'
The auto-decrement operator is not magical.
--
Keith C. Ivey <[EMAIL PROTECTED]>
Washington, DC
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web