尝试使用 AutoHotKey 通过剪贴板将十六进制加密为 base64

尝试使用 AutoHotKey 通过剪贴板将十六进制加密为 base64

我得到了一个可以将突出显示的 URL 解码为 base64 的代码。

现在我想将突出显示的十六进制编码为 base64,但我无法让它工作:/

例如,我们有十六进制:3648af61e4473d60d85481bf822a6d04316615efd6cd903d6bdc05b8c9ae58bfbabbb154099e345e4e12d770a774ad599420af221c26a7e0f21f9f1fc43a6d14 并希望对其进行 base64 编码。结果我得到了

MzY0OGFmNjFlNDQ3M2Q2MGQ4NTQ4MWJmODIyYTZkMDQzMTY2MTVlZmQ2Y2Q5MDNkNmJkYzA1YjhjOWFlNThiZmJhYmJiMTU0MDk5ZTM0NWU0ZTEyZDc3MGE3NzRhZDU5OTQyMGFmMjIxYzI2YTdlMGYyMWY5ZjFmYzQzYTZkMTQ=

但必须如此NkivYeRHPWDYVIG/giptBDFmFe/WzZA9a9wFuMmuWL+6u7FUCZ40Xk4S13CndK1ZlCCvIhwmp+DyH58fxDptFA==

我目前拥有的代码是

#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) . "="
}

我不知道如何得到正确的结果以及代码有什么问题?:(

相关内容