首页
社区
课程
招聘
[原创]RC4 加解密之 VBS 版
发表于: 2009-8-8 23:33 3760

[原创]RC4 加解密之 VBS 版

MPL 活跃值
1
2009-8-8 23:33
3760
用于处理VBS文件,不支持密钥含双字节字符的情况
Option Explicit	'MPL@bbs.pediy.com 2009-8-8

Const KEY = "MyPrettyLife"
Dim oFSO, oSrcFile, oDstFile, oSelfFile

CheckParam

Set oFSO = GetObject("", "Scripting.FileSystemObject")
Set oSrcFile = oFSO.GetFile(WSH.Arguments(0))
Set oDstFile = oFSO.CreateTextFile(oSrcFile.ParentFolder & "\RC4_" & oSrcFile.Name, True)

Set oSrcFile = oFSO.OpenTextFile(WSH.Arguments(0))
oDstFile.WriteLine "Execute GetStr(RC4(""" & KEY & """, """ & _
	RC4(KEY, SetStr(oSrcFile.ReadAll())) & """))"
oSrcFile.Close
Set oSrcFile = Nothing

Set oSelfFile = oFSO.OpenTextFile(WSH.ScriptFullName)
oDstFile.Write Split(oSelfFile.ReadAll(), "'----------------Share----------------")(2)
oSelfFile.Close
Set oSelfFile = Nothing

oDstFile.Close
Set oDstFile = Nothing
Set oFSO = Nothing

WSH.Echo "Done!"



Sub CheckParam()
	If WSH.Arguments.Count = 0 Then
		WSH.Echo "The File's Path Is Required!"
		WSH.Quit 1
	Else
		If Not CreateObject("Scripting.FileSystemObject") _
		.FileExists(WSH.Arguments(0)) Then
			WSH.Echo "File Not Found!"
			WSH.Quit 1
		End If
	End If
End Sub

Function SetStr(ByVal sSrc)
	Dim dst, i
	dst = ""
	For i = 1 To Len(sSrc)
		dst = dst & Asc(Mid(sSrc, i, 1)) & " "
	Next
	SetStr = RTrim(dst)
End Function
'----------------Share----------------
Function GetStr(ByVal sSrc)
	Dim dst, a, i
	a = Split(sSrc)
	dst = ""
	For i = 0 To UBound(a)
		dst = dst & Chr(a(i))
	Next
	GetStr = dst
End Function

Function RC4(ByVal sKey, ByVal sSrc)
	Dim S(255), i, j, key(), k, l, src, x, dst, subkey
	
	src = Split(sSrc)
	k = sKey
	l = Len(k)
	ReDim Preserve key(l - 1)
	For i = 0 To l - 1
		key(i) = Asc(Mid(k, i + 1, 1))
	Next
	
	'KSA
	For i = 0 To 255
		S(i) = i
	Next
	j = 0
	For i = 0 To 255	
		j = (j + S(i) + key(i Mod l)) Mod 256
		S(i) = S(i) + S(j)
		S(j) = S(i) - S(j)
		S(i) = S(i) - S(j)
	Next
	
	'PRGA
	i = 0
	j = 0
	dst = ""
	For x = 0 To UBound(src)
		i = (i + 1) Mod 256
		j = (j + S(i)) Mod 256
		S(i) = S(i) + S(j)
		S(j) = S(i) - S(j)
		S(i) = S(i) - S(j)
		subkey = S((S(i) + S(j)) Mod 256)
		dst = dst & CStr(subkey Xor CInt(src(x))) & " "
	Next

	RC4 = RTrim(dst)
End Function

[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 0
支持
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回
//