在你的應用程序里實現(xiàn)簡單的加密

字號:

下面的函數(shù)通過使用新的字符來替換原始的每一個字符而對值進行了加密。它先將每個字符轉(zhuǎn)換為其對應的ASCII值,再使用一個偏量,然后將(加入偏量的)ASCII值轉(zhuǎn)換回字符。這個偏量可以是從1到255之間的任何數(shù)。
    Public Function EncryptDecrypt(ByVal Value As String) As String
    Dim strChar As String
    Dim intCount As Integer
    Dim intASCII As Integer
    Dim strEncrypted As String
    Dim intOffset As Integer
    intOffset = 200
    strEncrypted = VBNullString
    For intCount = 1 To Len(Value)
    strChar = Mid$(Value, intCount, 1)
    intASCII = Asc(strChar) XorintOffset
    strEncrypted = strEncrypted & Chr(intASCII)
    Next intCount
    EncryptDecrypt = strEncrypted
    End Function
    要使用這個函數(shù),就要對你想要加密的值調(diào)用它。它會返回已經(jīng)過加密的值。要解密一個值,將它傳遞給這個函數(shù),它就會返回已解密的值。
    盡管這個函數(shù)對于簡單的加密要求來說是很有用的,但是它不應該被用來保護商業(yè)上的關(guān)鍵信息。這種加密法的簡單性就意味著它能夠被很快的*。