Advertisement
toan9xpro2012

URL Encode/Decode

Nov 16th, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.88 KB | None | 0 0
  1. Global $var[4] = [0,@DesktopWidth/2,@DesktopHeight/2]
  2. Global $va2[5] = [GUICreate('',$var[1],$var[2]),$var[2]-30,$var[1]/2,0]
  3. Global $GUI[5] = [GUICtrlCreateButton('Giải mã',$va2[2],$va2[1],$va2[2],30),GUICtrlCreateButton('Mã hóa',0,$va2[1],$va2[2],30),GUISetState(@SW_SHOW),GUICtrlCreateEdit('',0,0,$var[1],$va2[1])]
  4.  
  5. Func _UnicodeURLEncode($UnicodeURL)
  6.     $UnicodeBinary = StringToBinary ($UnicodeURL, 4)
  7.     $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
  8.     $UnicodeBinaryLength = StringLen($UnicodeBinary2)
  9.     Local $EncodedString
  10.     For $i = 1 To $UnicodeBinaryLength Step 2
  11.         $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
  12.         If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then
  13.             $EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar)
  14.         Else
  15.             $EncodedString &= '%' & $UnicodeBinaryChar
  16.         EndIf
  17.     Next
  18.     Return $EncodedString
  19. EndFunc   ;==>_UnicodeURLEncode
  20.  
  21. Func _UnicodeURLDecode($toDecode)
  22.     Local $strChar = "", $iOne, $iTwo
  23.     Local $aryHex = StringSplit($toDecode, "")
  24.     For $i = 1 To $aryHex[0]
  25.         If $aryHex[$i] = "%" Then
  26.             $i = $i + 1
  27.             $iOne = $aryHex[$i]
  28.             $i = $i + 1
  29.             $iTwo = $aryHex[$i]
  30.             $strChar = $strChar & Chr(Dec($iOne & $iTwo))
  31.         Else
  32.             $strChar = $strChar & $aryHex[$i]
  33.         EndIf
  34.     Next
  35.     $Process = StringToBinary (StringReplace($strChar, "+", " "))
  36.     $DecodedString = BinaryToString ($Process, 4)
  37.     Return $DecodedString
  38. EndFunc   ;==>_UnicodeURLDecode
  39.  
  40. While 1
  41.     Switch GUIGetMsg()
  42.         Case -3
  43.             Exit
  44.         Case $GUI[1]
  45.             GUICtrlSetData($GUI[3],_UnicodeURLEncode(GUICtrlRead($GUI[3])))
  46.         Case $GUI[0]
  47.             GUICtrlSetData($GUI[3],_UnicodeURLDecode(GUICtrlRead($GUI[3])))
  48.     EndSwitch
  49. WEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement