VBA MD5加密算法(转)
Private Const BITS_TO_A_BYTE =
Private Const BYTES_TO_A_WORD =
Private Const BITS_TO_A_WORD = Private m_lOnBits()
Private m_l2Power() Private Function LShift(lValue, iShiftBits)
If iShiftBits = Then
LShift = lValue
Exit Function
ElseIf iShiftBits = Then
If lValue And Then
LShift = &H80000000
Else
LShift =
End If
Exit Function
ElseIf iShiftBits < Or iShiftBits > Then
Err.Raise
End If If (lValue And m_l2Power( - iShiftBits)) Then
LShift = ((lValue And m_lOnBits( - (iShiftBits + ))) * m_l2Power(iShiftBits)) Or &H80000000
Else
LShift = ((lValue And m_lOnBits( - iShiftBits)) * m_l2Power(iShiftBits))
End If
End Function Private Function RShift(lValue, iShiftBits)
If iShiftBits = Then
RShift = lValue
Exit Function
ElseIf iShiftBits = Then
If lValue And &H80000000 Then
RShift =
Else
RShift =
End If
Exit Function
ElseIf iShiftBits < Or iShiftBits > Then
Err.Raise
End If RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits) If (lValue And &H80000000) Then
RShift = (RShift Or (&H40000000 \ m_l2Power(iShiftBits - )))
End If
End Function Private Function RotateLeft(lValue, iShiftBits)
RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, ( - iShiftBits))
End Function Private Function AddUnsigned(lX, lY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim lResult lX8 = lX And &H80000000
lY8 = lY And &H80000000
lX4 = lX And &H40000000
lY4 = lY And &H40000000 lResult = (lX And &H3FFFFFFF) + (lY And &H3FFFFFFF) If lX4 And lY4 Then
lResult = lResult Xor &H80000000 Xor lX8 Xor lY8
ElseIf lX4 Or lY4 Then
If lResult And &H40000000 Then
lResult = lResult Xor &HC0000000 Xor lX8 Xor lY8
Else
lResult = lResult Xor &H40000000 Xor lX8 Xor lY8
End If
Else
lResult = lResult Xor lX8 Xor lY8
End If AddUnsigned = lResult
End Function Private Function md5_F(x, y, z)
md5_F = (x And y) Or ((Not x) And z)
End Function Private Function md5_G(x, y, z)
md5_G = (x And z) Or (y And (Not z))
End Function Private Function md5_H(x, y, z)
md5_H = (x Xor y Xor z)
End Function Private Function md5_I(x, y, z)
md5_I = (y Xor (x Or (Not z)))
End Function Private Sub md5_FF(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_F(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub Private Sub md5_GG(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_G(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub Private Sub md5_HH(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_H(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub Private Sub md5_II(a, b, c, d, x, s, ac)
a = AddUnsigned(a, AddUnsigned(AddUnsigned(md5_I(b, c, d), x), ac))
a = RotateLeft(a, s)
a = AddUnsigned(a, b)
End Sub Private Function ConvertToWordArray(sMessage)
Dim lMessageLength
Dim lNumberOfWords
Dim lWordArray()
Dim lBytePosition
Dim lByteCount
Dim lWordCount Const MODULUS_BITS =
Const CONGRUENT_BITS = lMessageLength = Len(sMessage) lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + ) * (MODULUS_BITS \ BITS_TO_A_WORD)
ReDim lWordArray(lNumberOfWords - ) lBytePosition =
lByteCount =
Do Until lByteCount >= lMessageLength
lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(Asc(Mid(sMessage, lByteCount + , )), lBytePosition)
lByteCount = lByteCount +
Loop lWordCount = lByteCount \ BYTES_TO_A_WORD
lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition) lWordArray(lNumberOfWords - ) = LShift(lMessageLength, )
lWordArray(lNumberOfWords - ) = RShift(lMessageLength, ) ConvertToWordArray = lWordArray
End Function Private Function WordToHex(lValue)
Dim lByte
Dim lCount For lCount = To
lByte = RShift(lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits(BITS_TO_A_BYTE - )
WordToHex = WordToHex & Right("" & Hex(lByte), )
Next
End Function Public Function MD5(sMessage, stype)
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng()
m_lOnBits() = CLng() m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng()
m_l2Power() = CLng() Dim x
Dim k
Dim AA
Dim BB
Dim CC
Dim DD
Dim a
Dim b
Dim c
Dim d Const S11 =
Const S12 =
Const S13 =
Const S14 =
Const S21 =
Const S22 =
Const S23 =
Const S24 =
Const S31 =
Const S32 =
Const S33 =
Const S34 =
Const S41 =
Const S42 =
Const S43 =
Const S44 = x = ConvertToWordArray(sMessage) a = &H67452301
b = &HEFCDAB89
c = &H98BADCFE
d = &H10325476 For k = To UBound(x) Step
AA = a
BB = b
CC = c
DD = d md5_FF a, b, c, d, x(k + ), S11, &HD76AA478
md5_FF d, a, b, c, x(k + ), S12, &HE8C7B756
md5_FF c, d, a, b, x(k + ), S13, &H242070DB
md5_FF b, c, d, a, x(k + ), S14, &HC1BDCEEE
md5_FF a, b, c, d, x(k + ), S11, &HF57C0FAF
md5_FF d, a, b, c, x(k + ), S12, &H4787C62A
md5_FF c, d, a, b, x(k + ), S13, &HA8304613
md5_FF b, c, d, a, x(k + ), S14, &HFD469501
md5_FF a, b, c, d, x(k + ), S11, &H698098D8
md5_FF d, a, b, c, x(k + ), S12, &H8B44F7AF
md5_FF c, d, a, b, x(k + ), S13, &HFFFF5BB1
md5_FF b, c, d, a, x(k + ), S14, &H895CD7BE
md5_FF a, b, c, d, x(k + ), S11, &H6B901122
md5_FF d, a, b, c, x(k + ), S12, &HFD987193
md5_FF c, d, a, b, x(k + ), S13, &HA679438E
md5_FF b, c, d, a, x(k + ), S14, &H49B40821 md5_GG a, b, c, d, x(k + ), S21, &HF61E2562
md5_GG d, a, b, c, x(k + ), S22, &HC040B340
md5_GG c, d, a, b, x(k + ), S23, &H265E5A51
md5_GG b, c, d, a, x(k + ), S24, &HE9B6C7AA
md5_GG a, b, c, d, x(k + ), S21, &HD62F105D
md5_GG d, a, b, c, x(k + ), S22, &H2441453
md5_GG c, d, a, b, x(k + ), S23, &HD8A1E681
md5_GG b, c, d, a, x(k + ), S24, &HE7D3FBC8
md5_GG a, b, c, d, x(k + ), S21, &H21E1CDE6
md5_GG d, a, b, c, x(k + ), S22, &HC33707D6
md5_GG c, d, a, b, x(k + ), S23, &HF4D50D87
md5_GG b, c, d, a, x(k + ), S24, &H455A14ED
md5_GG a, b, c, d, x(k + ), S21, &HA9E3E905
md5_GG d, a, b, c, x(k + ), S22, &HFCEFA3F8
md5_GG c, d, a, b, x(k + ), S23, &H676F02D9
md5_GG b, c, d, a, x(k + ), S24, &H8D2A4C8A md5_HH a, b, c, d, x(k + ), S31, &HFFFA3942
md5_HH d, a, b, c, x(k + ), S32, &H8771F681
md5_HH c, d, a, b, x(k + ), S33, &H6D9D6122
md5_HH b, c, d, a, x(k + ), S34, &HFDE5380C
md5_HH a, b, c, d, x(k + ), S31, &HA4BEEA44
md5_HH d, a, b, c, x(k + ), S32, &H4BDECFA9
md5_HH c, d, a, b, x(k + ), S33, &HF6BB4B60
md5_HH b, c, d, a, x(k + ), S34, &HBEBFBC70
md5_HH a, b, c, d, x(k + ), S31, &H289B7EC6
md5_HH d, a, b, c, x(k + ), S32, &HEAA127FA
md5_HH c, d, a, b, x(k + ), S33, &HD4EF3085
md5_HH b, c, d, a, x(k + ), S34, &H4881D05
md5_HH a, b, c, d, x(k + ), S31, &HD9D4D039
md5_HH d, a, b, c, x(k + ), S32, &HE6DB99E5
md5_HH c, d, a, b, x(k + ), S33, &H1FA27CF8
md5_HH b, c, d, a, x(k + ), S34, &HC4AC5665 md5_II a, b, c, d, x(k + ), S41, &HF4292244
md5_II d, a, b, c, x(k + ), S42, &H432AFF97
md5_II c, d, a, b, x(k + ), S43, &HAB9423A7
md5_II b, c, d, a, x(k + ), S44, &HFC93A039
md5_II a, b, c, d, x(k + ), S41, &H655B59C3
md5_II d, a, b, c, x(k + ), S42, &H8F0CCC92
md5_II c, d, a, b, x(k + ), S43, &HFFEFF47D
md5_II b, c, d, a, x(k + ), S44, &H85845DD1
md5_II a, b, c, d, x(k + ), S41, &H6FA87E4F
md5_II d, a, b, c, x(k + ), S42, &HFE2CE6E0
md5_II c, d, a, b, x(k + ), S43, &HA3014314
md5_II b, c, d, a, x(k + ), S44, &H4E0811A1
md5_II a, b, c, d, x(k + ), S41, &HF7537E82
md5_II d, a, b, c, x(k + ), S42, &HBD3AF235
md5_II c, d, a, b, x(k + ), S43, &H2AD7D2BB
md5_II b, c, d, a, x(k + ), S44, &HEB86D391 a = AddUnsigned(a, AA)
b = AddUnsigned(b, BB)
c = AddUnsigned(c, CC)
d = AddUnsigned(d, DD)
Next If stype = Then
MD5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d))
Else
MD5 = LCase(WordToHex(b) & WordToHex(c))
End If
End Function
Sub test()
Dim i As String
i = InputBox("Please input a password:")
If MD5(i, ) = MD5("abc", ) Or MD5(i, ) = MD5("abc", ) Then: MsgBox "Ok": Else: MsgBox "failed": End
'MsgBox MD5("abc", 16) '16λ¼ÓÃÜ
'MsgBox MD5("abc", 32) '32λ¼ÓÃÜ
End Sub
VBA MD5加密算法(转)的更多相关文章
- 一起谈谈MD5加密算法
MD5是一个安全的散列算法,输入两个不同的明文不会得到相同的输出值,根据输出值,不能得到原始的明文,即其过程不可逆:所以要解密MD5没有现成的算法,只能用穷举法,把可能出现的明文,用MD5算法散列之后 ...
- MD5加密算法
package com.bao.tools.encryption; import java.security.MessageDigest;import java.security.NoSuchAlgo ...
- md5加密算法c语言版
from: http://blog.sina.com.cn/s/blog_693de6100101kcu6.html 注:以下是md5加密算法c语言版(16/32位) ---------------- ...
- MD5加密算法测试
在用户注册这一块,密码加密保证客户信息安全是最重要的,在网上查询了一些资料,发现加密算法比较流行的有MD5,DES和SHA. 虽然SHA与MD5通过碰撞法被破解了,但是MD5和SHA仍被公认是安全的加 ...
- 标准MD5加密算法
标准MD5加密算法: public class Md5 { public static String getMd5(String s) { char hexDigits[] = { '0', '1', ...
- MD5加密算法(java及js)
为了防止用户登陆过程中信息被拦截导致信息泄露,我们应该在客户端就对用户密码进行加密.浏览器提交给服务器的是加密后的信息,即使被恶意拦截,被拦截信息也已做了加密处理,现在比较安全的一种加密算法是MD5加 ...
- MD5加密算法的Java版本
网上搜索Java实现MD5的资料很多,错误的也很多. 之前编写的一个阿里云直播鉴权原理算法需要用到MD5算法,网上找了几个,都是不行,浪费了时间,现在贴一个,做备用. import java.secu ...
- JAVA实现MD5加密算法(使用MessageDigest)
http://blog.csdn.net/ymc0329/article/details/6738711 *********************************************** ...
- c++Builder XE6 MD5 加密算法 BASE64 URL 编码
xe6,xe7 BASE64XE6 MD5 加密算法Delphifunction MD5(const texto: string): string; var idmd5: TIdHashMessage ...
随机推荐
- 3.Bacula Client安装配置
1. Bacula Client安装配置 1.1. linux客户端安装 1.1.1. 安装依赖包 yum install libacl libacl-devel 1.1.2. Clien ...
- 008.MVC与数据库的交互
使用ASP.NET MVC实现向数据库插入数据的步骤(程序): (删除,修改,查找)步骤1:创建数据库,创建要使用的表(数据) 表中可以事先插入测试数据步骤2:新建项目,写代码2.1)在配置文件中设置 ...
- idea的使用问题解决
IDEA集成SVN插件,用的是TortoiseSVN,SVN上明明有别人提交的内容,但是我这里点击Incoming确显示不出来 解决方案:file->Invalidate Cache/Resta ...
- idea中iml文件的问题
idea中iml文件的问题 iml文件是idea组织工程的文件, 里面记录了各种记录模块, 文件夹以及依赖的信息, 显示如下: <?xml version="1.0" enc ...
- 打开myeclipse提示An internal error occurred during: "CheckLicensesAndNotify". com/genuitec/pulse2/client/targetcfg/ui/PulseActivator
打开myeclipse提示An internal error occurred during: "CheckLicensesAndNotify". com/genuitec/pul ...
- CentOS 6 自定义单实例 二进制方式 安装mariadb-5.5.59
系统平台: CentOS release 6.9 (Final) 内核 2.6.32-696.el6.x86_64 1.去官网下载适合的二进制包 http://mariadb.org/ mariadb ...
- 老瞎眼 pk 小鲜肉 (线段树)
链接:https://ac.nowcoder.com/acm/contest/1114/E来源:牛客网 题目描述 老瞎眼有一个长度为 n 的数组 a,为了为难小鲜肉,他准备了 Q 次询问,每次给出 一 ...
- Linux初始化脚本
以下脚本用于linux系统的初始化脚本,可以在服务器系统安装完毕之后立即执行.脚本结合各位大牛一些参数,已经在CentOS 5下通过. 使用方法:将其复制,保存为一个shell文件,比如init.sh ...
- python的内置函数(一)
1.数学计算函数 abs(x) 求绝对值1.参数可以是整型,也可以是复数2.若参数是复数,则返回复数的模 complex([real[, imag]]) 创建一个复数 divmod(a, b) 分别取 ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊 (LCT维护深度)
要维护深度,就维护一下size就行了.access一下x,那么从根->x这一条链就独立成为一棵splay,那么splay的size节点数就是x的深度. 删边的时候直接access一下,splay ...