These scripts are obsolete now. In XP+ you should use the Windows Crypto API, as Titan discovered:
Code:
;;;;; ----- Binary to base64/formatted-HEX conversion by the Crypto API, for XP+ (2HEX, 2Base64)
; http://msdn.microsoft.com/en-us/library/aa380285(VS.85).aspx
; http://www.autohotkey.com/forum/viewtopic.php?p=238120#238120
; fmt = 1:base64, 4:hex-table, 5:hex+ASCII, 10:offs+hex, 11:offs+hex+ASCII, 12:raw-hex
BinaryToString(ByRef bin, sz=0, fmt=12) { ; return base64 or formatted-hex
n := sz>0 ? sz : VarSetCapacity(bin)
DllCall("Crypt32.dll\CryptBinaryToStringA", UInt,&bin, UInt,n, UInt,fmt, UInt,0, UIntP,cp, "CDECL UInt") ; get size
VarSetCapacity(str,cp)
DllCall("Crypt32.dll\CryptBinaryToStringA", UInt,&bin, UInt,n, UInt,fmt, UInt,&str, UIntP,cp, "CDECL UInt")
Return str
}
StringToBinary(ByRef bin, hex, fmt=12) { ; return length, result in bin
DllCall("Crypt32.dll\CryptStringToBinaryA", UInt,&hex, UInt,StrLen(hex), UInt,fmt, UInt,0, UIntP,cp, UInt,0,UInt,0,"CDECL UInt") ; get size
VarSetCapacity(bin,cp)
DllCall("Crypt32.dll\CryptStringToBinaryA", UInt,&hex, UInt,StrLen(hex), UInt,fmt, UInt,&bin, UIntP,cp, UInt,0,UInt,0,"CDECL UInt")
Return cp
}
; TEST
VarSetCapacity(bin,100,122) ; 100 z-chars
fmt = 11 ; table: offs+hex+ASCII
MsgBox % hex:= BinaryToString(bin,100,fmt) ; encode
len := StringToBinary(bin1,hex,fmt) ; decode
VarSetCapacity(bin1,-1) ; use only with string in bin1
bin1 := SubStr(bin1,1,len) ; strip of garbage at the end
MsgBox %len%: %bin1% ; show len, original data