RC4 unicode support?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

RC4 unicode support?

14 Feb 2018, 07:45

I'm using https://github.com/ahkscript/libcrypt.a ... rc/RC4.ahk for RC4 Encryption/Decryption, but it doesn't support unicode characters.

The folowing code displays Paste your 数据 here, but the correct result should be Paste your 数据 here as shown in this online RC4 tool.
Image

Code: Select all

MsgBox % LC_RC4_Decrypt("CC0F1F0B6A005AA797149C55F4B2038A02496968A13A", "SECRET")

; https://github.com/ahkscript/libcrypt.ahk/blob/master/src/RC4.ahk
LC_RC4_Encrypt(Data,Pass) {
	Format:=A_FormatInteger,b:=0,j:=0,Key:=Object(),sBox:=Object()
	SetFormat,Integer,Hex
	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
}

LC_RC4_Decrypt(Data,Pass) {
	b:=0,j:=0,x:="0x",Key:=Object(),sBox:=Object()
	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
}
Can anyone help please?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mcd and 287 guests