Spread the love

How To Decrypt a URL or String In VbScript or UFT

Spread the love

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

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.

READ  VBScript DataTypes

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.




Spread the love
READ  When Automation Will Grow Up?
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Learn Object Repository in UFT in An Efficient and Fast Manner

Object Repository in UFT The post will cover the following topics Details...

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special...

Learn Object Repository in UFT in An Efficient and Fast Manner

Object Repository in UFT The post will cover the following...

Learn What Primary Tools For Test Automation

Primary Tools For Test Automation According to the Gartner report...

EDITOR PICKS


Spread the love