Linux可以用sha1sum命令来校验文件的sha1值,Windows下也不乏sha1校验的工具。其实自己实现一个简单的sha1sum程序并不难,只要知道sha1算法就可以了,不知道也不要紧,复制粘贴总会吧。
下面就是我“复制粘贴”出来的sha1sum程序,纯ANSI C实现。
[download id=56]
Linux可以用sha1sum命令来校验文件的sha1值,Windows下也不乏sha1校验的工具。其实自己实现一个简单的sha1sum程序并不难,只要知道sha1算法就可以了,不知道也不要紧,复制粘贴总会吧。
下面就是我“复制粘贴”出来的sha1sum程序,纯ANSI C实现。
[download id=56]
鉴于很多人反映之前写的那篇在XP下无效,做了一下修改。说是修改,其实是直接复制粘贴脚本专家的代码。
strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colEvents = objWMIService.ExecNotificationQuery _ ("Select * From __InstanceOperationEvent Within 10 Where " _ & "TargetInstance isa 'Win32_LogicalDisk'") Do While True Set objEvent = colEvents.NextEvent If objEvent.TargetInstance.DriveType = 2 Then Select Case objEvent.Path_.Class Case "__InstanceCreationEvent" Wscript.Echo "Drive " & objEvent.TargetInstance.DeviceId & _ " has been added." Case "__InstanceDeletionEvent" Wscript.Echo "Drive " & objEvent.TargetInstance.DeviceId & _ " has been removed." End Select End If Loop
参考链接:How Can I Determine When a Removable Drive Gets Connected?
Function md5_file(filename, raw_output) Dim HashedData, Utility, Stream Set HashedData = CreateObject("CAPICOM.HashedData") Set Utility = CreateObject("CAPICOM.Utilities") Set Stream = CreateObject("ADODB.Stream") HashedData.Algorithm = 3 Stream.Type = 1 Stream.Open Stream.LoadFromFile filename Do Until Stream.EOS HashedData.Hash Stream.Read(1024) Loop If raw_output Then md5_file = Utility.HexToBinary(HashedData.Value) Else md5_file = HashedData.Value End If End Function
参考链接:HashedData Object
Function sha1_file(filename, raw_output) Dim HashedData, Utility, Stream Set HashedData = CreateObject("CAPICOM.HashedData") Set Utility = CreateObject("CAPICOM.Utilities") Set Stream = CreateObject("ADODB.Stream") HashedData.Algorithm = 0 Stream.Type = 1 Stream.Open Stream.LoadFromFile filename Do Until Stream.EOS HashedData.Hash Stream.Read(1024) Loop If raw_output Then sha1_file = Utility.HexToBinary(HashedData.Value) Else sha1_file = HashedData.Value End If End Function
参考链接:HashedData Object
期末复习,差不多零点才回到宿舍。打开QQ,弹出一个半年不说一句话的群,高中班级的群。上大学以后大家都很忙吧,以至于一声问候也成了奢侈。或者说,已经不是同一个世界的人了。
群消息的内容就是问C语言注释的正则表达式,果然是无事不登三宝殿。他给的代码是:
\/\*(.|[\n])*(\*\/){1}
还说程序会一直匹配到最后一个*/,弄了半个下午没弄出来,烦死了。
这种问题Google一下不就行了么:
/\*(.|[\r\n])*?\*/
还是计算机专业的,连贪婪模式和非贪婪模式都不懂。我懂,但又怎样?
参考链接:Finding Comments in Source Code Using Regular Expressions