zoukankan      html  css  js  c++  java
  • 【VB】加密/解密函数

    对于连接字符串以及一些比较重要的信息需要加密的时候,用下面的函数是个不错的方法。从网上找个函数,已经测试过很好用。Share一下

     

    Code

    Function cipher(stext As String)    ‘加密程序

        Const min_asc = 32
        Const max_asc = 126
        Const num_asc = max_asc - min_asc + 1
        Dim offset As Long
        Dim strlen As Integer
        Dim i As Integer
        Dim ch As Integer
        Dim ptext As String
        offset = 123
        Rnd (-1)
        Randomize (offset)
        strlen = Len(stext)
        For i = 1 To strlen
           ch = Asc(Mid(stext, i, 1))
           If ch >= min_asc And ch <= max_asc Then
               ch = ch - min_asc
               offset = Int((num_asc + 1) * Rnd())
               ch = ((ch + offset) Mod num_asc)
               ch = ch + min_asc
               ptext = ptext & Chr(ch)
           End If
        Next i
        cipher = ptext
    End Function

    ---------


     

    Code

    Function decipher(stext As String)     --解密程序

        Const min_asc = 32  '最小Ascall码
        Const max_asc = 126 '最大Ascall码
        Const num_asc = max_asc - min_asc + 1
        Dim offset As Long
        Dim strlen As Integer
        Dim i As Integer
        Dim ch As Integer
        Dim ptext As String
        offset = 123
        Rnd (-1)
        Randomize (offset)
        strlen = Len(stext)
        For i = 1 To strlen
           ch = Asc(Mid(stext, i, 1))  ’取字母转换为Ascll码

           If ch >= min_asc And ch <= max_asc Then
               ch = ch - min_asc
               offset = Int((num_asc + 1) * Rnd())
               ch = ((ch - offset) Mod num_asc)
               If ch < 0 Then
                   ch = ch + num_asc
               End If
               ch = ch + min_asc
               ptext = ptext & Chr(ch)
           End If
        Next i
        decipher = ptext
    End Function

  • 相关阅读:
    HDOJ1269 迷宫城堡
    最长公共子序列 nyoj36
    HDU1081 To The Max 求子矩阵最大和
    nyoj20 吝啬的国度
    景观分析工具:arcgis中patch analysis模块
    景观格局动态变化分析方法(基于ArcGIS、Fragstats、ENVI、ERDAS、Patch Analysis for ArcGIS) (20110315 08:07:03)
    从C#到Python —— 谈谈我学习Python一周来的体会
    如何判定多边形是顺时针还是逆时针
    超新星与暗能量的发现--今年诺贝尔物理奖工作的介绍(转)
    怎样把扫描好的身份证打印出实际大小
  • 原文地址:https://www.cnblogs.com/cuishao1985/p/1516226.html
Copyright © 2011-2022 走看看