Skip to content

Instantly share code, notes, and snippets.

@leoloobeek
Last active June 6, 2023 08:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoloobeek/872f0636323d51b2d419be3058d1c4cd to your computer and use it in GitHub Desktop.
Save leoloobeek/872f0636323d51b2d419be3058d1c4cd to your computer and use it in GitHub Desktop.
In case you ever need VBS, RC4, and have base64 encrypted bytes. I'm probably the only person who did.
'https://bytes.com/topic/access/insights/906671-rc4-encryption-algorithm-vba-vbscript
' Note: There are known weaknesses to RC4 and should not be relied on
Function RC4(byteMessage, strKey)
Dim kLen, x, y, i, j, temp
Dim s(256), k(256)
For a = 0 To 255
s(a) = a
k(a) = 0
Next
klen = Len(strKey)
For i = 0 To 255
j = (j + s(i) + Asc(Mid(strKey, (i Mod klen) + 1, 1))) Mod 256
k(i) = j
temp = s(i)
s(i) = s(j)
s(j) = temp
Next
x = 0
y = 0
For i = 1 To LenB(byteMessage)
x = (x + 1) Mod 256
y = (y + s(x)) Mod 256
temp = s(x)
s(x) = s(y)
s(y) = temp
RC4 = RC4 & (s((s(x) + s(y)) Mod 256) Xor AscB(MidB(byteMessage, i, 1))) & ","
Next
End Function
function decodeBase64(base64)
dim DM, EL
Set DM = CreateObject("Microsoft.XMLDOM")
Set EL = DM.createElement("tmp")
EL.DataType = "bin.base64"
EL.Text = base64
decodeBase64 = EL.NodeTypedValue
end function
dim key, bytes
key = "strong key w/IV"
bytes = decodeBase64("base64==")
WScript.Echo RC4(bytes, key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment