注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

B4A字符串加解密类模块(二)  

2014-04-11 19:02:09|  分类: B.加密解密 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
StringCryptandDeCrypt 类模块代码如下


'Class module
Sub Class_Globals
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

End Sub

'加密字符串
'TheStr = 需要加密的文本
'KeyStr =密码文本
 Sub Crypt(TheStr As String ,KeyStr As String) As String
    Dim i As Int
    Dim FilpKeyStr As Long
    Dim X1 As Long
    Dim G As Long
    Dim Crypted As String
    Dim key As Long
    
    For i = 0 To KeyStr.Length-1
        FilpKeyStr = Asc(KeyStr.SubString2(i,i+1))
        X1 = X1 + FilpKeyStr
    Next
    X1 = Round((X1 * 0.1) / 6)
    key = X1
    G = 0
    For i = 0 To TheStr.Length-1
        FilpKeyStr = Asc(TheStr.SubString2(i,i+1))
        G = G + 1
        If G = 6 Then G = 0
        X1 = 0
        If G = 0 Then X1 = FilpKeyStr - (key - 2)
        If G = 1 Then X1 = FilpKeyStr + (key - 5)
        If G = 2 Then X1 = FilpKeyStr - (key - 4)
        If G = 3 Then X1 = FilpKeyStr + (key - 2)
        If G = 4 Then X1 = FilpKeyStr - (key - 3)
        If G = 5 Then X1 = FilpKeyStr + (key - 5)
        X1 = X1 + G
        Crypted = Crypted & Chr(X1)
    Next
    Return(Crypted)

End Sub

'解密字符串
'TheStr = 需要加密的文本
'KeyStr =密码文本
 Sub DeCrypt(TheStr, KeyStr) As String
    Dim i As Int
    Dim FilpKeyStr As Long
    Dim X1 As Long
    Dim G As Long
    Dim key As Long
    Dim DeCrypted As String
 
    For i =0 To KeyStr.Length-1
        FilpKeyStr = Asc(KeyStr.SubString2(i,i+1))
        X1 = X1 + FilpKeyStr
    Next
    X1 = Round((X1 * 0.1) / 6)
    key = X1
    G = 0
    
    For i = 0 To TheStr.Length-1
        FilpKeyStr = Asc(TheStr.SubString2(i,i+1))
        G = G + 1        
        If G = 6 Then G = 0
        X1 = 0
        If G = 0 Then X1 = FilpKeyStr + (key - 2)
        If G = 1 Then X1 = FilpKeyStr - (key - 5)
        If G = 2 Then X1 = FilpKeyStr + (key - 4)
        If G = 3 Then X1 = FilpKeyStr - (key - 2)
        If G = 4 Then X1 = FilpKeyStr + (key - 3)
        If G = 5 Then X1 = FilpKeyStr - (key - 5)
        X1 = X1 - G
        DeCrypted = DeCrypted & Chr(X1)
    Next
    Return(DeCrypted)
   
End Sub

  评论这张
 
阅读(177)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017