ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 3189|回复: 4

[分享] 字附串加密函数(安全性较高的加密方式)

[复制链接]

TA的精华主题

TA的得分主题

发表于 2009-1-1 16:46 | 显示全部楼层 |阅读模式
最近写了一个小小的系统,用到了ACCESS数据库,由于ACCESS数据库安全性不太高,不得不对数据进行层层加密,现将字附串的加密方法与大家分享.

[ 本帖最后由 彭希仁 于 2009-1-3 23:46 编辑 ]
12.JPG

TA的精华主题

TA的得分主题

发表于 2009-1-1 17:16 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
不错的异或位操作的例子,帮顶。

happy new year

TA的精华主题

TA的得分主题

发表于 2009-1-1 17:34 | 显示全部楼层
decode

Sub tt()
    MsgBox jami("student", "new year")
    MsgBox jami(jami("student", "new year"), "new year")
End Sub

Function jami(x As String, y As String) As String
    Dim datx() As Byte
    Dim daty() As Byte
    datx = x
    daty = y
    j = 0
    For i = 0 To UBound(datx)
        If j > UBound(daty) Then j = 0
        If datx(i) <> daty(j) Then datx(i) = datx(i) Xor daty(j)
        j = j + 1
    Next i
    jami = datx
End Function

[ 本帖最后由 xiangchendub 于 2009-1-1 17:38 编辑 ]

TA的精华主题

TA的得分主题

 楼主| 发表于 2009-1-3 22:54 | 显示全部楼层
安全性较高的加密方案.

Function jami(XX, YY) As String  
    Dim datx() As Byte, datx1() As Byte
    Dim daty() As Byte
    Dim X As String, y As String, h As Long
    X = XX
    y = YY
    daty = y
    If "jami@" = Mid(X, 1, 5) Then  
        X = Mid(X, 6, Len(X))
        arr = Split(X, " ")
        ReDim datx(UBound(arr)) As Byte
        For i = 0 To UBound(arr)
            datx(i) = arr(i)
        Next i
    Else
        datx = X
        For i = 0 To UBound(datx) - 1 Step 2
            If datx(i) = 255 And datx(i + 1) = 255 Then
                datx(i) = 0: datx(i + 1) = 0
            End If
        Next i
    End If
    j = 0
    datx1 = datx
    For i = 0 To UBound(datx)
        If j > UBound(daty) Then j = 0
        datx(i) = datx(i) Xor daty(j)
        j = j + 1
    Next i

    For i = UBound(datx) - 1 To 2 Step -2
        h = datx(i)
        h = Abs(h - datx1(i))
        datx(i - 2) = datx(i - 2) Xor h
    Next i
    For i = 0 To UBound(datx) - 1 Step 2         '这里便是存在问题的根源,但又不得不这样做,要不然存入EXCEL单无格之后不能保持文本的原样.
        If datx(i) = 0 And datx(i + 1) = 0 Then
            datx(i) = 255: datx(i + 1) = 255
        End If
    Next i
    jami = datx
  If jami2(jami, y) <> XX And "jami@" <> Mid(XX, 1, 5) Then    '加密后用解密进行验证,如果出错,换数字的方式来显示.
        datx = datx1
        j = 0
        For i = 0 To UBound(datx)
            If j > UBound(daty) Then j = 0
            datx(i) = datx(i) Xor daty(j)
            j = j + 1
        Next i
        For i = UBound(datx) - 1 To 2 Step -2
            h = datx(i)
            h = Abs(h - datx1(i))
            datx(i - 2) = datx(i - 2) Xor h
        Next i
        X = datx(0)
        For i = 1 To UBound(datx)
            X = X & " " & datx(i)
        Next i
        jami = "jami@" & X
End If
End Function
Function jami2(XX, YY) As String   '存在65536分之1的错误机率的加密方法,这里主要用来还原验证
    Dim datx() As Byte, datx1() As Byte
    Dim daty() As Byte
    Dim X As String, y As String, h As Long
    X = XX
    y = YY
    datx = X
    daty = y
    j = 0
    For i = 0 To UBound(datx) - 1 Step 2
        If datx(i) = 255 And datx(i + 1) = 255 Then
            datx(i) = 0: datx(i + 1) = 0
        End If
    Next i
    datx1 = datx
    For i = 0 To UBound(datx)
        If j > UBound(daty) Then j = 0
        datx(i) = datx(i) Xor daty(j)
        j = j + 1
    Next i

    For i = UBound(datx) - 1 To 2 Step -2
        h = datx(i)
        h = Abs(h - datx1(i))
        datx(i - 2) = datx(i - 2) Xor h
    Next i
    For i = 0 To UBound(datx) - 1 Step 2
        If datx(i) = 0 And datx(i + 1) = 0 Then
            datx(i) = 255: datx(i + 1) = 255
        End If
    Next i
    jami2 = datx
End Function

[ 本帖最后由 彭希仁 于 2009-1-3 23:33 编辑 ]

TA的精华主题

TA的得分主题

发表于 2009-6-14 17:01 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-11 22:53 , Processed in 0.027245 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表