Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires AutoHotkey >= v2.0 ; Ensures that you're using AHKv2
- #SingleInstance Force ; Only 1 instance of the script can run
- test()
- ExitApp()
- *Esc::ExitApp
- test(){
- ; SGVsbG8sIHdvcmxkIQ==
- txt := "Hello, world!"
- enc := buf64_encode(txt)
- dec := buf64_decode(enc)
- MsgBox "start: " txt
- . "`nencode: " enc
- . "`ndecode: " dec
- }
- buf64_encode(strIn, encoding := "UTF-8") {
- static CRYPT_STRING_BASE64 := 0x1
- if (encoding = "UTF-8")
- suffix := "A"
- else
- suffix := "W"
- ,encoding := "UTF-16"
- bufStr := Buffer(StrPut(strIn, encoding))
- StrPut(strIn, bufStr, encoding)
- chars := Buffer(4, 0)
- if !DllCall("Crypt32\CryptBinaryToString" suffix
- ,"Ptr" ,bufStr ; const BYTE *pbBinary,
- ,"UInt" ,bufStr.Size ; DWORD cbBinary,
- ,"UInt" ,CRYPT_STRING_BASE64 ; DWORD dwFlags,
- ,"Ptr" ,0 ; LPWSTR pszString,
- ,"Ptr" ,chars) ; DWORD *pcchString
- MsgBox("Error getting chars")
- strOut := Buffer(NumGet(chars, "UInt"), 0)
- if !DllCall("Crypt32\CryptBinaryToString" suffix
- ,"Ptr" ,bufStr ; const BYTE *pbBinary,
- ,"UInt" ,bufStr.Size ; DWORD cbBinary,
- ,"UInt" ,CRYPT_STRING_BASE64 ; DWORD dwFlags,
- ,"Ptr" ,strOut ; LPWSTR pszString,
- ,"Ptr" ,chars) ; DWORD *pcchString
- MsgBox("Error getting string")
- return StrGet(strOut, encoding)
- }
- buf64_decode(strIn, encoding := "UTF-8") {
- static CRYPT_STRING_BASE64 := 0x1
- if (encoding = "UTF-8")
- suffix := "A"
- else
- suffix := "W"
- ,encoding := "UTF-16"
- bufStr := Buffer(StrPut(strIn, encoding))
- StrPut(strIn, bufStr, encoding)
- chars := Buffer(4, 0)
- if (!DllCall("Crypt32\CryptStringToBinary" suffix
- ,"Ptr" , bufStr ;[in] LPCSTR pszString,
- ,"UInt" , bufStr.Size ;[in] DWORD cchString,
- ,"UInt" , CRYPT_STRING_BASE64 ;[in] DWORD dwFlags,
- ,"Ptr" , 0 ;[in] BYTE *pbBinary,
- ,"Ptr" , chars ;[in, out] DWORD *pcbBinary,
- ,"Ptr" , 0 ;[out] DWORD *pdwSkip,
- ,"Ptr" , 0 )) ;[out] DWORD *pdwFlags
- MsgBox "Error getting decode size"
- strOut := Buffer(NumGet(chars, "UInt"))
- if (!DllCall("Crypt32\CryptStringToBinary" suffix
- ,"Ptr" , bufStr ;[in] LPCSTR pszString,
- ,"UInt" , bufStr.Size ;[in] DWORD cchString,
- ,"UInt" , CRYPT_STRING_BASE64 ;[in] DWORD dwFlags,
- ,"Ptr" , strOut ;[in] BYTE *pbBinary,
- ,"Ptr" , chars ;[in, out] DWORD *pcbBinary,
- ,"Ptr" , 0 ;[out] DWORD *pdwSkip,
- ,"Ptr" , 0 )) ;[out] DWORD *pdwFlags
- MsgBox "Error getting decode size"
- return StrGet(strOut, encoding)
- }
Add Comment
Please, Sign In to add comment