0
votes

I have code

Function DeCrypt(strName)
  if strName <> ""  then   
    g_KeyLocation = "m:\mysvr_src\mycart_svr.txt"
    'g_Key = mid(ReadKeyFromFile(g_KeyLocation),1,Len(strName))
    g_Key="gsovjrcenzhqjxigkhuhkfmabwxuzsuexvypfohbkmhdilihfbvhgfzccckvafoazynbhyeexinfwmeaesjzhwtqyaaybvghxwyfmewamhqwygaaqcbjklyeblidcvapajwdumodndhdkaauzxqnohrgvezmznbmtfyuadkbjrdbedjwsarlqpejrzszqdlkngwfdlphnswqewdtedwensocyqcryzkxtegmarfkiycyhloatbwtcxyzdyvpwjcovvtqodlxegmzletfxpiejlomorotgnpxeybqsclioisuoixvanwndpnerpyfaudkdivpjukeualkmgdkmpfvjszpxmqzcjwrfurmkolbibhvedqlsqzbyzdhqdicjqxesbhjtrskogydnhnndjviusctgipptulmdyhfhkkvxkajkazedplpuganevendeqcvgjeyaqvugfmupexcdlyvucdumrwmapofseeqvpyopfonhfgmsmjxrmdoztsqqnk"
    count = 1
    while InStr(strname,"_")
      iKeyChar = (Asc(mid(g_Key,count,1)))
      strName = Mid(strName,2,len(strName)-1) 
      if InStr(strName,"_")-1 = -1 then 
        iStringChar = strName
      else
        iStringChar = Mid(strName,1,InStr(strName,"_")-1)
      end if 
      iDeCryptChar = iKeyChar Xor iStringChar
      strDecrypted = strDecrypted & Chr(iDeCryptChar) 
      strName = Right(strName,len(strName)-instr(strName,"_")+1)
      count = count + 1
    wend
    deCrypt = strDecrypted 
  else
    deCrypt = ""
  end if
End Function

I got some right result and then it stop and show me this error:

Microsoft VBScript runtime error '800a000d'
Type mismatch: 'iStringChar'

The error is in this line:

iDeCryptChar = iKeyChar Xor iStringChar
1

1 Answers

1
votes

The error is actually rather self-explanatory. You can't XOR an integer with a string. Of course you'll get a type mismatch.

Change this:

if InStr(strName,"_")-1 = -1 then 
  iStringChar = strName
else
  iStringChar = Mid(strName,1,InStr(strName,"_")-1)
end if 

into this:

if InStr(strName,"_")-1 = -1 then
  iStringChar = Asc(strName)
else
  iStringChar = Asc(Mid(strName,1,InStr(strName,"_")-1))
end if