Click to See Complete Forum and Search --> : Encryption


Llam4
09-26-2003, 07:28 PM
I've coded this script for javascript and it is meant to list 30 possiblilities, in order, of an ascii shift. Heres the code:


<html>
<head>
<script language="JavaScript">
function decrypt()
{
var encrypted=document.form1.decrypt.value
var decrypted=0
var i = 0
var j = 0

for (j = 0; j < 30; j++)
{
for (i = 0; i < document.form1.decrypt.value.length; i++)
{
decrypted[i] = encrypted[i] + j
}
document.write(j + ". " + decrypted + "<br>")
}
}
</script>
</head>
<body bgcolor="#000000" color="#FFFFFF">
<form action="" name="form1" method="POST">
<input type=text name="decrypt" maxlength="99999">
<input type=button onClick=decrypt() value=decrypt>
</form>
</body>
</html>


It doesn't work, as probably some of you experts/(even noobs)? could tell. Please help me fix it because all internet explorer can do is tell me i have an error.

Jeff Mott
09-26-2003, 07:40 PM
The variable encrypted is a string and decrypted is a number, but you treat both as an array...

Llam4
09-26-2003, 07:44 PM
ive tried setting decrypted = "" but same error

Llam4
09-26-2003, 08:00 PM
I have "updated" my code although I may have jsut screwed it up more. Here is the script as it is now but it stil ldoesn't work. Any help would be appreciated:


<html>
<head>
<script language="JavaScript">
function decrypt()
{
var encrypted= new String(document.form1.decrypt.value);
var decrypted= new String("");
var i = 0
var j = 0

for (j = 1; j < 30; j++)
{
for (i = 0; i < document.form1.decrypt.value.length; i++)
{
decrypted.charCodeAt(i) = encrypted.charCodeAt(i) + j
}
document.write(j + ". " + decrypted + "<br>")
}
}
</script>
</head>
<body bgcolor="#000000" color="#FFFFFF">
<form action="" name="form1" method="POST">
<input type=text name="decrypt" maxlength="99999">
<input type=button onClick=decrypt() value=decrypt>
</form>
</body>
</html>

Jeff Mott
09-26-2003, 09:16 PM
decrypted.charCodeAt(i) = encrypted.charCodeAt(i) + jMethods cannot be assigned to. It might be easier to create character arrays from your encrypted/decrypted strings.function decrypt()
{
var encrypted = [];
var decrypted = [];

for (var i = 0; i < document.form1.decrypt.value.length; ++i)
encrypted[i] = document.form1.decrypt.value.charCodeAt(i);

for (var i = 0; i < 30; ++i) {
for (var j = 0; j < document.form1.decrypt.value.length; ++j)
decrypted[j] = encrypted[j] + i
document.write(i + ". " + decrypted.join('') + "<br>");
}
}