/    Sign up×
Community /Pin to ProfileBookmark

Help with Array Manipulation

Hi Guys, first time using javascript and i need wee bit of help. I am developing a simple encypyt decrypt script, and I am using charCodeAt() to assign each char a number, i have got this far but now I need to cube that number and put it in a new array, how do i do this:

thanks in advance

<html>
<body>

<script type=”text/javascript”>

var e = “no data”;

function encrypt(form){
if(form.input.value ==””) alert(e);
else {var plaintext = form.input.value.split(” “);
for(i = 0; i < plaintext.length; i++){
document.write(“<br /> Element ” + i + ” = ” + plaintext[i]);
document.write(plaintext[i].charCodeAt(0)); //need to cube (plaintext[i].charCodeAt(0) and output to new array

}

}
}

</script>

<center>
<form name=encryptform>
<table>
<tr>
<td align=center>Original String</td>
<td> </td>
<td align=center>Encrypted Code</td>
</tr>
<tr>
<td align=center><input name=input type=text size=40></td>
<td align=center>
<input type=button value=”Decrypt” onClick=”javascript:decrypt(this.form)”><br>
<input type=button value=”Encrypt” onClick=”javascript:encrypt(this.form)”>
</td>
<td align=center><input name=output type=text size=40></td>
</tr>
</table>
</form>
</center>

</body>
</html>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Mar 22.2008 — [code=php]
var e = "no data";
var newArray = [];
function encrypt(form){
if(form.input.value =="") alert(e);
else {var plaintext = form.input.value.split(" ");
for(i = 0; i < plaintext.length; i++){
document.write("<br /> Element " + i + " = " + plaintext[i]);
document.write(plaintext[i].charCodeAt(0)); //need to cube (plaintext[i].charCodeAt(0) and output to new array
newArray.push(Math.pow(plaintext[i].charCodeAt(0),3))


}

}
}
[/code]
Copy linkTweet thisAlerts:
@uncle_gimoahauthorMar 22.2008 — thank you so much, been playing with it for ages.
Copy linkTweet thisAlerts:
@uncle_gimoahauthorMar 22.2008 — I have used the unicode number to translate the char into a number using charCodeAt(). How to I reverse this, by converting back to a char. or is there a better way.

Tanks

[code=php]function encrypt(form){
if(form.input.value =="") alert(e);
else {var plaintext = form.input.value.split(" ");
for(i = 0; i < plaintext.length; i++){
document.write("<br /> Element " + i + " = " + plaintext[i]);
document.write(plaintext[i].charCodeAt(0));
cubed.push(Math.pow(plaintext[i].charCodeAt(0),3));
document.write("<br /> cubed " + i + " = " + cubed[i]);
modd.push((cubed[i]) % 33);
document.write("<br /> modd 33 " + i + " = " + modd[i]);

[/code]
×

Success!

Help @uncle_gimoah 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.18,
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,
)...