Eu tenho um código que decodificará o URL destacado para base64.
Agora gosto de codificar um hexadecimal destacado para base64, mas não consigo trabalhar: /
Como exemplo, temos hexadecimal: 3648af61e4473d60d85481bf822a6d04316615efd6cd903d6bdc05b8c9ae58bfbabbb154099e345e4e12d770a774ad599420af221c26a7e0f21f9f1fc43a6d14
e quer codificar essa base64. Como resultado, obtenho
MzY0OGFmNjFlNDQ3M2Q2MGQ4NTQ4MWJmODIyYTZkMDQzMTY2MTVlZmQ2Y2Q5MDNkNmJkYzA1YjhjOWFlNThiZmJhYmJiMTU0MDk5ZTM0NWU0ZTEyZDc3MGE3NzRhZDU5OTQyMGFmMjIxYzI2YTdlMGYyMWY5ZjFmYzQzYTZkMTQ=
mas deve ser NkivYeRHPWDYVIG/giptBDFmFe/WzZA9a9wFuMmuWL+6u7FUCZ40Xk4S13CndK1ZlCCvIhwmp+DyH58fxDptFA==
O código que tenho até agora é
#SingleInstance, Force
;***********Decode URL*******************
!d:: ;Alt+d will Decode highlighted text from URL to base64
gosub Store_Clipboard_Copy_Selected_Text
Clipboard:=URiDecode(clipboard) ;Decode URL
Gosub Paste_and_Restore_Stored_Clipboard ;restore clipboard
return
;***********Decode HEX*******************
!f:: ;Alt+f will Encode highlighted text from Hex to base64
gosub Store_Clipboard_Copy_Selected_Text
Clipboard:=Base64Encode(clipboard) ; Encode HEX
Gosub Paste_and_Restore_Stored_Clipboard ;restore clipboard
return
;*******Store Clipboard- save for restoring, and copy selected text to clipboard****************
Store_Clipboard_Copy_Selected_Text:
Store:=ClipboardAll ;Store full version of Clipboard
clipboard = ; Empty the clipboard
SendInput, ^c ;changd from Send 11/23
ClipWait, 1
If ErrorLevel ;Added errorLevel checking
{
MsgBox, No text was sent to clipboard
Return
}
return
;**********************restore clipboard*********************************
Paste_and_Restore_Stored_Clipboard: ;put back original content
SendEvent , ^v
Clipboard:=Store
return
uriDecode(str) {
Loop
If RegExMatch(str, "i)(?<=%)[\da-f]{1,2}", hex)
StringReplace, str, str, '%%hex%, % Chr("0x" . hex), All
Else Break
Return, str
}
Base64Encode(String)
{
static CharSet := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
VarSetCapacity(Output,Ceil(Length / 3) << 2)
Index := 1, Length := StrLen(String)
Loop, % Length // 3
{
Value := Asc(SubStr(String,Index,1)) << 16
| Asc(SubStr(String,Index + 1,1)) << 8
| Asc(SubStr(String,Index + 2,1))
Index += 3
Output .= SubStr(CharSet,(Value >> 18) + 1,1)
. SubStr(CharSet,((Value >> 12) & 63) + 1,1)
. SubStr(CharSet,((Value >> 6) & 63) + 1,1)
. SubStr(CharSet,(Value & 63) + 1,1)
}
Length := Mod(Length,3)
If Length = 0 ;no characters remaining
Return, Output
Value := Asc(SubStr(String,Index,1)) << 10
If Length = 1
{
Return, Output ;one character remaining
. SubStr(CharSet,(Value >> 12) + 1,1)
. SubStr(CharSet,((Value >> 6) & 63) + 1,1) . "=="
}
Value |= Asc(SubStr(String,Index + 1,1)) << 2 ;insert the third character
Return, Output ;two characters remaining
. SubStr(CharSet,(Value >> 12) + 1,1)
. SubStr(CharSet,((Value >> 6) & 63) + 1,1)
. SubStr(CharSet,(Value & 63) + 1,1) . "="
}
Eu não vejo como obter o resultado correto e o que há de errado com o código? : (