/    Sign up×
Community /Pin to ProfileBookmark

Problem with for loops, functions, and XOR-ing…

Hey guys,

I am trying to make a script that lets people encrypt their email in their webpage. However I can seem to get it to work.

I’ve tried many many different combinations and positions of the code but it always comes up with trivial errors that should be easy to fix… but aren’t.

Heres the code that you can chuck in a browser to see what happens.

[code]
<html>
<head>
<title>Encrypt the email address on your page</title>
</head>

<body>

<script language=”javascript”>

//var d=”document”, w=”write”;
var encrypt, decrypt, email, et;

document.write(“<form name=”ef”>”);
document.write(“Email address: <input type=’text’ name=”txtemail”><br />”);
document.write(“Encryption: <input type=’text’ name=”txtet”><br />”);
document.write(“<button onclick=”execute();”>Encrypt</button>”);

function execute()
{
email=document[“ef”][“txtemail”].value;
et=document[“ef”][“txtet”].value;

document.write(“<input type=’hidden’ name=”encrypted” value=””);
for(i=0;i<email.length;i++)
{
document.write(String.fromCharCode(et^email.charCodeAt(i)));
}
document.write(“”>”);
encrypt=document[“ef”][“encrypted”].value;
document.write(“<input type=”hidden” name=”decrypted” value=””);
for(i=0;i<encrypt.length;i++)
{
document.write(String.fromCharCode(et^encrypt.charCodeAt(i)));
}
document.write(“”>”);

decrypt=document[“ef”][“decrypted”].value;
document.write(“Encrypted Form: <div style=’font-color: blue;’>”+encrypt);
document.write(“</div>”);
document.write(“Decrypted Form: <div style=’font-color: blue;’>”+decrypt);
document.write(“</div>”);
}

document.write(“</form>”);

</script>

</body>
</html>
[/code]

Right now it gives me a [b]document.ef.encrypted is not an object[/b] error in IE 5 and an [b]email is not defined[/b] error in Firefox 1.0.3 (Javascript Console).

It is really confusing… help is much appreciated…

Cheers
hamstar

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @hamstar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...