Click to See Complete Forum and Search --> : Beginner needs helping hand...


ordertv
04-21-2004, 01:30 AM
Hi everyone, need a bit of help. Trying to create a script that will decode an encoded email address. Doing a simple encoding and just need a script to decode it. Example, this is the best I have so far. If this is the example email address after being encoded
pd908x3david007!z3r2cyahooooo%com%au
need the decoder to:
1. remove the random text from the beginning (pd908x3)
2. turn the next string to and "@" (!z3r2c)
3. turn all "%"'s into "."'s
The desired output would be david007@yahooooo.com.au.

What I have so far removes other characters as well...for example it removes the d's adn 0's and I am getting avi7@yahooooo.com.au . I know it is because these letters/numbers are in the random text I am removing, but don't know how to fix. I assume I need to somehow define them as a string. Below is what I have so far...and suggestions or simplifications would be great!

<!-- Begin
function replaceChars(entry) {
out = "!z3r2c"; // replace this
add = "@"; // with this
temp = "" + entry; // temporary holder

while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add +
temp.substring((pos + out.length), temp.length));
}
out2 = "%"; // replace this
add2 = "."; // with this
temp2 = "" + temp; // temporary holder

while (temp2.indexOf(out2)>-1) {
pos= temp2.indexOf(out2);
temp2 = "" + (temp2.substring(0, pos) + add2 +
temp2.substring((pos + out2.length), temp2.length));
}
{
s = temp2;
filteredValues = "pd908x3"; // Characters stripped out
var i;
var returnString = "";
for (i = 0; i < s.length; i++) { // Search through string and append to unfiltered values to returnString.
var c = s.charAt(i);
if (filteredValues.indexOf(c) == -1) returnString += c;
}}
document.subform.text.value = returnString;
}
// End -->
</script>
</HEAD>

<BODY>

<center>
<form name="subform">

<input type=text name=text size=80 value="Enter value here..."><br>
<input type=button name=action value="Enter Data then Click Here" onClick="replaceChars(document.subform.text.value);">

<!-- Or to make it change when the user clicks the next -->
<!-- field, use this instead of the previous two lines: -->

<!-- <input type=text name=text size=80 value="Enter value here..." onBlur="replaceChars(this.value);"> -->