How To Decrypt a URL or String In VbScript or UFT

Test Automation As a Service

To encrypt and decrypt the best options to avail to go to the online site and transform what we need.
Few good sites could be as follows:

How To Decrypt a URL or String In VbScript or UFT

for base 64 decoding

Ads code goes here

But I tried to understand what was the logic behind it:
I searched google and found one link in StackOverflow.
https://stackoverflow.com/questions/4998715/does-vba-have-any-built-in-url-decoding
Mitch Wheat’s Solution


Public Function URLDecode(ByVal strEncodedURL As String) As String
   Dim str As String
   str = strEncodedURL 
   If Len(str) > 0 Then
      str = Replace(str, "&amp", " & ")
      str = Replace(str, "&#03", Chr(39))
      str = Replace(str, "&quo", Chr(34))
      str = Replace(str, "+", " ")
      str = Replace(str, "%2A", "*")
      str = Replace(str, "%40", "@")
      str = Replace(str, "%2D", "-")
      str = Replace(str, "%5F", "_")
      str = Replace(str, "%2B", "+")
      str = Replace(str, "%2E", ".")
      str = Replace(str, "%2F", "/")
URLDecode = str
End If<
End Function
How To Decrypt a URL or String In VbScript or UFT

This code was not perfect the writer of the code has given some idea how to do it. He has also mentioned one link for a better approach- http://www.freevbcode.com/ShowCode.asp?ID=1512. But this is in VB. My objective is to get the same in VBScript so that I can work with UFT.

Markus Diersbock' solution:


Public Function URLDecode(sEncodedURL As String) As String
On Error GoTo Catch
Dim
iLoop As Integer
sRtn As String
sTmp As String
If Len(sEncodedURL) > 0 Then
' Loop through each char
For iLoop = 1 To Len(sEncodedURL)
sTmp = Mid(sEncodedURL, iLoop, 1)
sTmp = Replace(sTmp, "+", " ")
' If char is % then get next two chars
' and convert from HEX to decimal
If sTmp = "%" and LEN(sEncodedURL) + 1 > iLoop + 2 Then
sTmp = Mid(sEncodedURL, iLoop + 1, 2)
sTmp = Chr(CDec("&H" & sTmp))
' Increment loop by 2
iLoop = iLoop + 2
End If
sRtn = sRtn & sTmp
Next
URLDecode = sRtn
End If

Finally:
Exit Function
Catch:
URLDecode = ""
Resume Finally
End Function

But these solutions were not enough. I read in the wiki about Percent-encoding -
and the RFC 3986. I have also gone through the reserved character after percent encoding. When I was developing the same I found one more site with exactly the solution I was looking for: MarcusJT has provided the exact solution to implement the decoding functionality in VBScript. The code he has used is written below:


Function URLDecode(str)
str = unescape(str)
str = replace(str,"+"," ")
str = replace(str,"%2A","*")
str = replace(str,"%40","@")
str = replace(str,"%2D","-")
str = replace(str,"%5F","_")
str = replace(str,"%2B","+")
str = replace(str,"%2E",".")
str = replace(str,"%2F","/")
URLDecode = str
End Function

As per him, this functionality was given in Microsoft's Netscape JS in the form of escape() and unescape() function. There is a superior version available called server.URLEncode. VBScript's decode functionality is full of flaws. But this code served most of my URL or string decoding.

Share and Enjoy !

READ  VB Script Procedures and Functions

2 thoughts on “How To Decrypt a URL or String In VbScript or UFT”

Leave a Comment

Your email address will not be published. Required fields are marked *