MD5不可逆加密算法的ASP实现实例

2016-01-29 18:34 5 1 收藏

MD5不可逆加密算法的ASP实现实例,MD5不可逆加密算法的ASP实现实例

【 tulaoshi.com - ASP 】

  <%
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32

Private m_lOnBits(30)
Private m_l2Power(30)

Private Function LShift(lValue, iShiftBits)
    If iShiftBits = 0 Then
        LShift = lValue
        Exit Function
    ElseIf iShiftBits = 31 Then
        If lValue And 1 Then
            LShift = &H80000000
        Else
            LShift = 0
        End If
        Exit Function
    ElseIf iShiftBits < 0 Or iShiftBits 31 Then
        Err.Raise 6
    End If

    If (lValue And m_l2Power(31 - iShiftBits)) Then
        LShift = ((lValue And m_lOnBits(31 - (iShiftBits + 1))) * m_l2Power(iShiftBits)) Or &H80000000
    Else
        LShift = ((lValue And m_lOnBits(31 - iShiftBits)) * m_l2Power(iShiftBits))
    End If
End Function

Private Function RShift(lValue, iShiftBits)
    If iShiftBits = 0 Then
        RShift = lValue
        Exit Function
    ElseIf iShiftBits = 31 Then
        If lValue And &H80000000 Then
            RShift = 1
        Else
            RShift = 0
        End If
        Exit Function
    ElseIf iShiftBits < 0 Or iShiftBits 31 Then
        Err.Raise 6
    End If
    
    RShift = (lValue And &H7FFFFFFE) m_l2Power(iShiftBits)

    If (lValue And &H80000000) Then
        RShift = (RShift Or (&H40000000 m_l2Power(iShiftBits - 1)))
    End If
End Function

Private Function RotateLeft(lValue, iShiftBits)
    RotateLeft = LShift(lValue, iShiftBits) Or RShift(lValue, (32 - 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
  

来源:https://www.tulaoshi.com/n/20160129/1506425.html

延伸阅读
DES加密介绍 DES是一种对称加密算法,所谓对称加密算法即:加密和解密使用相同密钥的算法。DES加密算法出自IBM的研究,后来被美国政府正式采用,之后开始广泛流传,但是近些年使用越来越少,因为DES使用56位密钥,以现代计算能力,24小时内即可被破解。虽然如此,在某些简单应用中,我们还是可以使用DES加密算法,本文简单讲解DES的JAVA实现...
标签: ASP
  简介 首先简单介绍一下有关加密的背景。由于美国禁止几种密码算法的对外出口的 加密位数(例如SSL的40位加密限制),本文将介绍一种ASP可以使用的简单字符加密算法, 而不是那些受限制的加密算法。其实,这里介绍的加密算法对于一般的运用来说已经足够 解密人麻烦一阵子的了。它的加密基础是最简单的Vernum密码方法,我...
标签: ASP
  在第一部分,讨论了如何生成密钥,下面将介绍如何使用这个密钥来加密和解密一个 字符串。 下面的代码就是能够同时实现这个功能的函数 Crypt.asp文件 <% Dim g_Key Const g_CryptThis = "Now is the time for all good men to come to the aid of their country." Const g_KeyLocati...
我以为这个是大家都知道的所以没发出来,那天有网友问起我才觉得很多入门者其实是需要的。发出来给入门者看。 //原来写在一个webservice里所以有后面的者一串[WebMethod(Description="提供两种散列加密算法:MD5、SHA1。大小写敏感。")] public string EncryptPassword(string PasswordString,string PasswordFormat) { string result="";...
IBM的MARS加密算法实现(下) 作者:西安 吴真 IBM的MARS加密算法实现(上) 2.3 密文解密 用于密文解密的40个子密钥的生成和明文加密时的40个子密钥的生成方法相同. 2.3.1 第一步前向混合 输入的128位密文分成四块D[0],D[1],D[2],D[3],选取生成的40个密钥的最...

经验教程

539

收藏

9
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部