I'm trying to convert 2 functions from C to Javascript, but I'm failing on that.
The C functions im trying to convert is:
void encrypt(char password[],int key)
{
unsigned int i;
for(i=0;i<strlen(password);++i)
{
password[i] = password[i] - key;
}
}
void decrypt(char password[],int key)
{
unsigned int i;
for(i=0;i<strlen(password);++i)
{
password[i] = password[i] + key;
}
}
The C functions is from: http://c-program-example.com/2012/04/c-program-to-encrypt-and-decrypt-a-password.html
What i did in Javascript is this:
var password = "hello"
var key = 322424;
for (var i=0; i<password.length; i++) {
var char = password[i].charCodeAt();
var s = String.fromCharCode(char-key);
alert(s);
}
I'm putting the alert to see if it working correctly before making them as functions. Can someone please show me how it is done correctly in Js?