Simple REG EX - ... (Posted by Malte)
Hey,
could somebody please post the code for switching every character in a string n-times forward in alphabetical order (a->b, b->c, ...), and to reverse the process.
Thanks In Advance,
Malte
----------
Malte Ubl - [red]Germany[/red] - http://www.schaffhausen-interactive.de/
[red]The beats of 1000 hearts inside...[/red]
Federico Carnales posted this at 21:11 — 8th November 1999.
They have: 69 posts
Joined: Apr 1999
I'm sure there's a better way to do it, but here's my code anyway:
$offset = 1;
$string = "Hello there!";
@letters = (a..z,A..Z);
sub getnew {
$letter = shift;
$i = 0;
$valid = 0;
for (@letters) {
if ($letter eq $_) {
$valid = 1;
$newchar = $letters[($i+$offset)];
}
$i++;
}
if (!$valid) {
$newchar = $letter;
}
return $newchar;
}
print "content-type: text/html\n\n";
print "<p>Original string: $string</p>\n";
print "<p>Converted string: ";
(@chars) = split(//, $string);
for (@chars) {
print &getnew($_);
}
print "</p>";
Output:
Original string: Hello there!
Converted string: Ifmmp uifsf!
Regards,
Federico Carnales
----------
Reviews of the best resources for webmasters in your e-mail every week!
Subscribe for [red]FREE[/red] by going to http://www.web-reviews.com/
Federico Carnales posted this at 21:13 — 9th November 1999.
They have: 69 posts
Joined: Apr 1999
1) To undo the process change $letters[($i+$offset)]; to $letters[($i-$offset)];
2) If you want to change numbers too, change @letters = (a..z,A..Z); to @letters = (0..9,a..z,A..Z);
----------
Reviews of the best resources for webmasters in your e-mail every week!
Subscribe for [red]FREE[/red] by going to http://www.web-reviews.com/
Malte posted this at 21:19 — 9th November 1999.
They have: 297 posts
Joined: Apr 1999
Thanx very much. I got it to work perfectly.
Malte
----------
Malte Ubl - [red]Germany[/red] - http://www.schaffhausen-interactive.de/
[red]The beats of 1000 hearts inside...[/red]
Malte posted this at 03:57 — 10th November 1999.
They have: 297 posts
Joined: Apr 1999
Is it enough to change the $i++ into $i-- to undo the process?
Thanx,
Malte
----------
Malte Ubl - [red]Germany[/red] - http://www.schaffhausen-interactive.de/
[red]The beats of 1000 hearts inside...[/red]
Malte posted this at 04:41 — 10th November 1999.
They have: 297 posts
Joined: Apr 1999
...and what happens to numbers?
JP Stones posted this at 23:01 — 10th November 1999.
They have: 2,390 posts
Joined: Nov 1998
what was it for?
JP
----------
[red]The Next Step in Website Development [/red] - http://www.what-next.com
The Webmaster Promotion and Resource Center
Malte posted this at 02:54 — 11th November 1999.
They have: 297 posts
Joined: Apr 1999
To decode information in an URL for a gift tracking service. Its not really supposed to be secure. It's just supposed to hide the reason for why we know who the person is (Because its hidden in the URL)
Later,
Malte
----------
Malte Ubl - [red]Germany[/red] - http://www.schaffhausen-interactive.de/
[red]The beats of 1000 hearts inside...[/red]
sumengen posted this at 20:04 — 20th November 1999.
They have: 15 posts
Joined: Jun 2000
You can do it in one line and in a much faster way using tr/// .
tr/a-zA-Z/b-zaB-ZB/;
if you also want to translate numbers:
tr/0-9a-zA-Z/1-90b-zaB-ZB/;
Baris.
------------------
Baris Sumengen
http://turkiyem.com/turkscripts
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.