<2007年8月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

统计

  • 随笔 - 24
  • 文章 - 0
  • 评论 - 17
  • 引用 - 0

常用链接

留言簿(4)

随笔分类

随笔档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜

VBScript写的计算异或的一个小工具
工作中经常会需要计算一大串字节的异或,用计算器手工一个一个的输入太累人了,碰巧这两天在关注VBScript,于是就想到写了这个工具。这是我第一次用VB,代码很简单,希望能对你有用。

'==========================================================================
'
'
'
 NAME: calc_xor.vbs
'
'
 COMMENT: Calculates the result of 'xor' all elements in the input
'
'
==========================================================================

Option Explicit

Dim strInput

'Promt for string to search for in log files
strInput = InputBox("Enter data to calc on.","calc xor","")

if strInput = "" then
    wscript.quit
end If

'MsgBox(Len(strInput))

Dim arrayBytes()
ReDim arrayBytes(Len(strInput)/2)

Dim i,nBytes
Dim chHalf1,chHalf2,chWhole
= 1
nBytes 
= 0

Do While (i < Len(strInput))
'Skip spaces between elements
Do While Asc(Mid(strInput,i,1)) = 32 'space
    i = i + 1
Loop 

    chHalf1 
= Asc(Mid(strInput,i,1))
    chHalf2 
= Asc(Mid(strInput,i+1,1))
    
'Check and convert first half

    
If chHalf1 >= 48 And chHalf1 <= 57 Then
        chHalf1 
= chHalf1 - 48
    
ElseIf chHalf1 >= 65 And chHalf1 <= 70 Then
        chHalf1 
= chHalf1 - 65 + 10
    
ElseIf chhalf1 >= 97 And chHalf1 <= 104 Then
        chHalf1 
= chHalf1 - 97 + 10
    
Else
        
MsgBox("invalid character")
        wscript.quit
    
End If
    
    
' Check and convert the second half
    If chHalf2 >= 48 And chHalf2 <= 57 Then
        chHalf2 
= chHalf2 - 48
    
ElseIf chHalf2 >= 65 And chHalf2 <= 70 Then
        chHalf2 
= chHalf2 - 65 + 10
    
ElseIf chHalf2 >= 97 And chHalf2 <= 104 Then
        chHalf2 
= chHalf2 - 97 + 10
    
Else
        
MsgBox("invalid character")
        wscript.quit
    
End If
    
    
' Combine the first and second halves together to form a whole byte
    chWhole = chHalf1 * 16 + chHalf2
    arrayBytes(nBytes) 
= chWhole
    i 
= i + 2
    nBytes 
= nBytes + 1
Loop

'MsgBox(CStr(nBytes) + " bytes all together")

Dim WshSHell
set WshShell = CreateObject("WScript.Shell")
WshShell.Run(
"calc")
WScript.Sleep(
100)
WshShell.AppActivate(
"Calculator")
WScript.Sleep(
100)

WshShell.SendKeys(
"{F6}"'Change to Decimal
'
WshShell.SendKeys("{F4}") 'Change to single byte
WScript.Sleep(100)
WshShell.SendKeys(
"0")
For i =1 to nBytes
    WshShell.SendKeys(
"{^}")
    WScript.Sleep(
100)
    WshShell.SendKeys(arrayBytes(i
-1))
    WScript.Sleep(
100)
    WshShell.SendKeys(
"{=}")
    WScript.Sleep(
100)
Next

WshShell.SendKeys(
"{F5}"'Change to Hex for easy recognition



posted on 2007-08-03 13:05 小葱蘸酱 阅读(1243) 评论(0)  编辑 收藏 引用 所属分类: 编码点滴


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理