Link to home
Start Free TrialLog in
Avatar of greenrc
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
Avatar of b1xml2
b1xml2
Flag of Australia image

function JSEncrypt(str,strPwd) {
     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;
}
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;
}
ASKER CERTIFIED SOLUTION
Avatar of b1xml2
b1xml2
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of greenrc
greenrc

ASKER

thank you for your assitance.