程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB綜合教程 >> 一個簡單實用的 vb 加密/解密算法

一個簡單實用的 vb 加密/解密算法

編輯:VB綜合教程

Function UserCode(password As String) As String
'用戶口令加密
    Dim il_bit, il_x, il_y, il_z, il_len, i As Long
    Dim is_out As String
    il_len = Len(password)
    il_x = 0
    il_y = 0
    is_out = ""
    For i = 1 To il_len
        il_bit = AscW(Mid(password, i, 1))    'W系列支持unicode
       
        il_y = (il_bit * 13 Mod 256) + il_x
        is_out = is_out & ChrW(Fix(il_y))  '取整 int和fix區別: fix修正負數
        il_x = il_bit * 13 / 256
    Next
    is_out = is_out & ChrW(Fix(il_x))
   
    password = is_out
    il_len = Len(password)
    il_x = 0
    il_y = 0
    is_out = ""
    For i = 1 To il_len
        il_bit = AscW(Mid(password, i, 1))
        '取前4位值
        il_y = il_bit / 16 + 64
        is_out = is_out & ChrW(Fix(il_y))
        '取後4位值
        il_y = (il_bit Mod 16) + 64
        is_out = is_out & ChrW(Fix(il_y))
    Next
    UserCode = is_out
End Function
Function UserDeCode(password As String) As String
'口令解密
    Dim is_out As String
    Dim il_x, il_y, il_len, i, il_bit As Long

    il_len = Len(password)
    il_x = 0
    il_y = 0
    is_out = ""
    For i = 1 To il_len Step 2
        il_bit = AscW(Mid(password, i, 1))
        '取前4位值
        il_y = (il_bit - 64) * 16
        '取後4位值
        'dd = AscW(Mid(password, i + 1, 1)) - 64
        il_y = il_y + AscW(Mid(password, i + 1, 1)) - 64
        is_out = is_out & ChrW(il_y)
    Next

    il_x = 0
    il_y = 0
    password = is_out
    is_out = ""

    il_len = Len(password)
    il_x = AscW(Mid(password, il_len, 1))  

    For i = (il_len - 1) To 1 Step -1
        il_y = il_x * 256 + AscW(Mid(password, i, 1))
        il_x = il_y Mod 13
        is_out = ChrW(Fix(il_y / 13)) & is_out
    Next
    UserDeCode = is_out
End Function

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved