I need to take data from a textarea on a website and decrypt it using a simple algorithm. The data is in the form of numbers separated by a comma. It also needs to read a space as a space. It looks like 42,54,57, ,57,40,57,44.
Heres what I have so far:
var my_textarea = $('textarea[name = "words"]').first();
var my_value = $(my_textarea).val();
var my_array = my_value.split(",");
for (i=0; i < my_array.length; i++)
{
var nv = my_array - 124;
var acv = nv + 34;
var my_result = String.fromCharCode(acv);
}
prompt("", my_result);
I have no idea what you were doing with the
nvandacvvariables, but I got your code working with a bit of modification.Firstly, you need to refer to the individual array piece with
my_array[i]inside your for loop. Secondly, it will not treat a blank space as a space unless you tell it to – you need to put in a check for a blank space, and turn it into a space character(32).The completed(and working) code is thus:
DEMO