@dadepp: Thank you!
So here it is;
UNICODE encryption for AutoHotkey_L unicode
Code:
;===Description=========================================================================
; UNICODE encryption for AutoHotkey_L unicode
; put together by Learning one using Laszlo's and dadepp's code. Thank you!
; ===Example===
Pass = MyPassword
Data = AutoHotkey_L unicode is great! 123 žćčšđ ŽĆČŠĐ
EncodedData := UnicodeEncode(Data,Pass)
MsgBox, % "Encoded to:`n" EncodedData
DecodedData := UnicodeDecode(EncodedData,Pass)
MsgBox, % "Decoded to:`n" DecodedData
ExitApp
;===Functions===========================================================================
UnicodeEncode(Data,Pass) {
utf7Data:=utf7encode(Data)
return RC4txt2hex(utf7Data,Pass)
}
UnicodeDecode(Data,Pass) {
Decoded2utf7 := RC4hex2txt(Data,Pass)
return utf7decode(Decoded2utf7)
}
Utf7Encode(s){
utf7Size := DllCall("WideCharToMultiByte", "UInt", 65000, "UInt", 0, "UInt", &s, "Int", -1, "Int", 0, "Int", 0, "Int", 0, "Int", 0)
VarSetCapacity(utf7String, utf7Size)
DllCall("WideCharToMultiByte", "UInt", 65000, "UInt", 0, "UInt", &s, "Int", -1, "Str", utf7String, "Int", utf7Size, "Int", 0, "Int", 0)
UniSize := DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &utf7String, "Int", -1, "Int", 0, "Int", 0)
VarSetCapacity(UniBuf, UniSize * 2)
DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &utf7String, "Int", -1, "UInt", &UniBuf, "Int", UniSize)
return UniBuf
}
Utf7Decode(s){
AnsiSize := DllCall("WideCharToMultiByte", "UInt", 0, "UInt", 0, "UInt", &s, "Int", -1, "Int", 0, "Int", 0, "Int", 0, "Int", 0)
VarSetCapacity(AnsiString, AnsiSize)
DllCall("WideCharToMultiByte", "UInt", 0, "UInt", 0, "UInt", &s, "Int", -1, "Str", AnsiString, "Int", AnsiSize, "Int", 0, "Int", 0)
UniSize := DllCall("MultiByteToWideChar", "UInt", 65000, "UInt", 0, "UInt", &AnsiString, "Int", -1, "Int", 0, "Int", 0)
VarSetCapacity(UniBuf, UniSize * 2)
DllCall("MultiByteToWideChar", "UInt", 65000, "UInt", 0, "UInt", &AnsiString, "Int", -1, "UInt", &UniBuf, "Int", UniSize)
return UniBuf
}
RC4txt2hex(Data,Pass) {
Format := A_FormatInteger
SetFormat Integer, Hex
b := 0, j := 0
VarSetCapacity(Result,StrLen(Data)*2)
Loop 256
a := A_Index - 1
,Key%a% := Asc(SubStr(Pass, Mod(a,StrLen(Pass))+1, 1))
,sBox%a% := a
Loop 256
a := A_Index - 1
,b := b + sBox%a% + Key%a% & 255
,sBox%a% := (sBox%b%+0, sBox%b% := sBox%a%) ; SWAP(a,b)
Loop Parse, Data
i := A_Index & 255
,j := sBox%i% + j & 255
,k := sBox%i% + sBox%j% & 255
,sBox%i% := (sBox%j%+0, sBox%j% := sBox%i%) ; SWAP(i,j)
,Result .= SubStr(Asc(A_LoopField)^sBox%k%, -1, 2)
StringReplace Result, Result, x, 0, All
SetFormat Integer, %Format%
Return Result
}
RC4hex2txt(Data,Pass) {
b := 0, j := 0, x := "0x"
VarSetCapacity(Result,StrLen(Data)//2)
Loop 256
a := A_Index - 1
,Key%a% := Asc(SubStr(Pass, Mod(a,StrLen(Pass))+1, 1))
,sBox%a% := a
Loop 256
a := A_Index - 1
,b := b + sBox%a% + Key%a% & 255
,sBox%a% := (sBox%b%+0, sBox%b% := sBox%a%) ; SWAP(a,b)
Loop % StrLen(Data)//2
i := A_Index & 255
,j := sBox%i% + j & 255
,k := sBox%i% + sBox%j% & 255
,sBox%i% := (sBox%j%+0, sBox%j% := sBox%i%) ; SWAP(i,j)
,Result .= Chr((x . SubStr(Data,2*A_Index-1,2)) ^ sBox%k%)
Return Result
}
Should I post that in Scripts & Functions?