For encryption and decryption the best options to avail to go to the online site and transform what we need.
Few good sites could be as follows:
- https://extendsclass.com/url-encode.html(my personal choice)
for base 64 decoding
- https://extendsclass.com/base64-decode-encode.html(my personal choice)
But I tried to understand what was the logic behind it:
I searched google and found one link in StackOverflow.
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, "&", " & ") str = Replace(str, "", 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
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 Dim sRtn As String Dim 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.