greenrc
asked on
port VBscript Encrypt function to javascript
Can someone please assist me porting this VBscript to javascript... having trouble with ASNI and Unicode
Function Encrypt(str,strPwd)
returnstr = ""
For i = 1 to len(str)
c = Asc(Mid(str,i,1))
c = c + Asc(Mid(strPwd, (i Mod Len(strPwd)) + 1, 1))
returnstr = returnstr & Chr(c And &HFF)
Next
' returnstr = str
Encrypt = returnstr
End Function
Function Decrypt(str,strPwd)
returnstr = ""
For i = 1 to len(str)
c = Asc(Mid(str,i,1))
c = c - Asc(Mid(strPwd, (i Mod Len(strPwd)) + 1, 1))
returnstr = returnstr & Chr(c And &HFF)
Next
' returnstr = str
Decrypt = returnstr
End Function
Function Encrypt(str,strPwd)
returnstr = ""
For i = 1 to len(str)
c = Asc(Mid(str,i,1))
c = c + Asc(Mid(strPwd, (i Mod Len(strPwd)) + 1, 1))
returnstr = returnstr & Chr(c And &HFF)
Next
' returnstr = str
Encrypt = returnstr
End Function
Function Decrypt(str,strPwd)
returnstr = ""
For i = 1 to len(str)
c = Asc(Mid(str,i,1))
c = c - Asc(Mid(strPwd, (i Mod Len(strPwd)) + 1, 1))
returnstr = returnstr & Chr(c And &HFF)
Next
' returnstr = str
Decrypt = returnstr
End Function
oops, again
===========
function JSEncrypt(str,strPwd) {
var returnstr = "";
var c = 0;
for (var i=1;i<str.length + 1;i++) {
c = str.charCodeAt(i - 1);
c += strPwd.charCodeAt(i % strPwd.length);
returnstr += String.fromCharCode(c & 255);
}
return returnstr;
}
function JSDecrypt(str,strPwd) {
var returnstr = "";
var c = 0;
for (var i=1;i<str.length + 1;i++) {
c = str.charCodeAt(i - 1);
c -= strPwd.charCodeAt(i % strPwd.length);
returnstr += String.fromCharCode(c & 255);
}
return returnstr;
}
===========
function JSEncrypt(str,strPwd) {
var returnstr = "";
var c = 0;
for (var i=1;i<str.length + 1;i++) {
c = str.charCodeAt(i - 1);
c += strPwd.charCodeAt(i % strPwd.length);
returnstr += String.fromCharCode(c & 255);
}
return returnstr;
}
function JSDecrypt(str,strPwd) {
var returnstr = "";
var c = 0;
for (var i=1;i<str.length + 1;i++) {
c = str.charCodeAt(i - 1);
c -= strPwd.charCodeAt(i % strPwd.length);
returnstr += String.fromCharCode(c & 255);
}
return returnstr;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you for your assitance.
var returnstr = "";
var data = "";
var c = 0;
for (var i=1;i<str.length + 1;i++) {
c = str.charCodeAt(i - 1);
c += strPwd.charCodeAt(i % strPwd.length);
returnstr += String.fromCharCode(c & 255);
}
return returnstr;
}
function JSDecrypt(str,strPwd) {
var returnstr = "";
var c = 0;
for (var i=1;i<str.length + 1;i++) {
c = str.charCodeAt(i - 1);
c -= strPwd.charCodeAt(i % strPwd.length);
returnstr += String.fromCharCode(c & 255);
}
return returnstr;
}