使用VBA生成短哈希字符串 [英] Generate short hash string based using VBA
本文介绍了使用VBA生成短哈希字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种VBA函数,该函数根据字符串内容生成一个非常短的哈希码(例如3个字符)
I'm looking for a VBA function that generates a very short hash code, say 3 characters, based on a string content
推荐答案
来自: http://www.lammertbies.nl/forum/viewtopic.php?t=302
Sub CRC16()
Dim x As Long
Dim mask, i, j, nC, Crc As Integer
Dim c As String
txt = "Now is the time for all good BEMs to come to the aid of the mothership"
Crc = &HFFFF ' crc mit $ffff initalisieren
For nC = 1 To Len(txt) Step 2
j = Val("&H" + Mid(txt, nC, 2)) 'im HEX-Format
Crc = Crc Xor j
For j = 1 To 8
mask = 0
If Crc / 2 <> Int(Crc / 2) Then mask = &HA001
Crc = Int(Crc / 2) And &H7FFF: Crc = Crc Xor mask
Next j
Next nC
txt = Hex$(Crc) 'Checksumme
End Sub
这篇关于使用VBA生成短哈希字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文