• Plaintext Encryption


    怎样才能更好的加密一段字符串?MD5、RSA、DES?

    好吧,这些都不懂。

    参考了一下度娘,所以想法是:

    对于加密:

    · 从待加密字符串中取出一个字符

    · 取字符的低字节和Key1进行异或运算

    · 取字符的高字节

    · 将运算后的数据合成新的字符

    对于解密:

    · 从待解密字符串中取出一个字符

    · 取字符的低字节和Key1进行异或运算

    · 取字符的高字节

    · 将运算后的数据合成新的字符

    有了方法,可以完成下面的函数:

    本加密方法只用于英文,中文也可以加密,但无法解密...

    加密 (Encryption):

    Private Function Encrypt(ByVal StrSource As String) As String    '加密
    Dim BLowData As Byte
    Dim BHigData As Byte
    Dim SHigData As Byte
    Dim i As Long
    Dim k As Integer
    Dim StrEncrypt As String
    Dim StrChar As String
    
    Dim KeyTemp As String
    Dim Key1 As Byte
        For k = 1 To 30
        KeyTemp = KeyTemp & CStr(Int(Rnd * (9) + 1))
        Next
        Key1 = CByte(Mid(KeyTemp, 11, 1) & Mid(KeyTemp, 27, 1))
        For i = 1 To Len(StrSource)
        StrChar = Mid(StrSource, i, 1)  '从待加密字符串中取出一个字符
        BLowData = AscB(MidB(StrChar, 1, 1)) Xor Key1    '取字符的低字节和Key1进行异或运算
        SHigData = AscB(MidB(StrChar, 2, 1))   '取字符的高字节
        StrEncrypt = StrEncrypt & ChrB(BLowData) & ChrB(BHigData)    '将运算后的数据合成新的字符
        Next i
        Encrypt = KeyTemp & StrEncrypt
    End Function

    解密(Decryption):

    Private Function Decrypt(ByVal StrSource As String) As String     '解密
    Dim BLowData As Byte
    Dim BHigData As Byte
    Dim i As Long
    Dim k As Integer
    Dim StrDecrypt As String
    Dim StrChar As String
    Dim KeyTemp As String
    Dim Key1 As Byte
    KeyTemp = Mid(StrSource, 1, 30)
    Key1 = CByte(Mid(KeyTemp, 11, 1) & Mid(KeyTemp, 27, 1))
    For i = 31 To Len(StrSource)
    StrChar = Mid(StrSource, i, 1)    '从待解密字符串中取出一个字符
    BLowData = AscB(MidB(StrChar, 1, 1)) Xor Key1   '取字符的低字节和Key1进行异或运算
    BHigData = AscB(MidB(StrChar, 2, 1))      '取字符的高字节
    StrDecrypt = StrDecrypt & ChrB(BLowData) & ChrB(BHigData)   '将运算后的数据合成新的字符
    Next i
    Decrypt = StrDecrypt
    End Function


    另外,考虑到加密字符的复杂性,建立一个command用来复制到剪贴板:

    Private Sub copyl_Click()
    Clipboard.Clear
    Clipboard.SetText (jiemit.Text)
    End Sub


    所以:

    Option Explicit
    'Copyright (c) 2014,烟台大学计算机学院
    'All right reserved.
    '作者:邵帅
    '文件:工程1.vsp
    '完成时间:2015年2月26日
    '版本号:v1.0.1
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Const WM_SYSCOMMAND = &H112
    Private Const SC_MOVE = &HF010&
    Private Const HTCAPTIO = 2
    Private Function Encrypt(ByVal StrSource As String) As String    '加密
    Dim BLowData As Byte
    Dim BHigData As Byte
    Dim SHigData As Byte
    Dim i As Long
    Dim k As Integer
    Dim StrEncrypt As String
    Dim StrChar As String
    
    Dim KeyTemp As String
    Dim Key1 As Byte
        For k = 1 To 30
        KeyTemp = KeyTemp & CStr(Int(Rnd * (9) + 1))
        Next
        Key1 = CByte(Mid(KeyTemp, 11, 1) & Mid(KeyTemp, 27, 1))
        For i = 1 To Len(StrSource)
        StrChar = Mid(StrSource, i, 1)  '从待加密字符串中取出一个字符
        BLowData = AscB(MidB(StrChar, 1, 1)) Xor Key1    '取字符的低字节和Key1进行异或运算
        SHigData = AscB(MidB(StrChar, 2, 1))   '取字符的高字节
        StrEncrypt = StrEncrypt & ChrB(BLowData) & ChrB(BHigData)    '将运算后的数据合成新的字符
        Next i
        Encrypt = KeyTemp & StrEncrypt
    End Function
    Private Function Decrypt(ByVal StrSource As String) As String     '解密
    Dim BLowData As Byte
    Dim BHigData As Byte
    Dim i As Long
    Dim k As Integer
    Dim StrDecrypt As String
    Dim StrChar As String
    Dim KeyTemp As String
    Dim Key1 As Byte
    KeyTemp = Mid(StrSource, 1, 30)
    Key1 = CByte(Mid(KeyTemp, 11, 1) & Mid(KeyTemp, 27, 1))
    For i = 31 To Len(StrSource)
    StrChar = Mid(StrSource, i, 1)    '从待解密字符串中取出一个字符
    BLowData = AscB(MidB(StrChar, 1, 1)) Xor Key1   '取字符的低字节和Key1进行异或运算
    BHigData = AscB(MidB(StrChar, 2, 1))      '取字符的高字节
    StrDecrypt = StrDecrypt & ChrB(BLowData) & ChrB(BHigData)   '将运算后的数据合成新的字符
    Next i
    Decrypt = StrDecrypt
    End Function
    
    Private Sub clearl_Click()
    jiamit.Text = ""
    jiemit.Text = ""
    End Sub
    
    Private Sub close_Click()
    End
    End Sub
    
    Private Sub copyl_Click()
    Clipboard.Clear
    Clipboard.SetText (jiemit.Text)
    End Sub
    
    Private Sub Image1_Click()
    
    End Sub
    
    Private Sub jiamil_Click()
    jiemit.Text = Encrypt(jiamit.Text)
    End Sub
    
    Private Sub jiemil_Click()
    jiemit.Text = Decrypt(jiemit.Text)
    End Sub
    
    Private Sub labFormTitle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        ReleaseCapture 'WM_SYS向窗体发送一个移动窗体命令
        Call SendMessage(Me.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTIO, 0)
    'SC_MOVE+ HTCAPTIO表示单击左键移动窗体
    End Sub
    
    Private Sub mini_Click()
    If Me.WindowState = 0 Then
      Me.WindowState = 1
    End If
    End Sub
    

    好吧,顺便写了一个UI,纯英文界面,高大上有木有,还能学习英文,因为写了这段代码,我知道了加密和解密的英文写法。

          


    满满的字符,瞬间猜不透了有木有。 

    下载:

    Plaintext Encryption


    @ Mayuko




  • 相关阅读:
    使用MyBatis生成插件
    关联源码及日志
    下载依赖
    框架简介及基本使用
    注解的本质 及 反射读取属性值
    元注解
    广告系统学习笔记(一)
    Nginx学习笔记(三)
    Nginx学习笔记(二)
    Nginx学习笔记(一)
  • 原文地址:https://www.cnblogs.com/mayuko/p/4567549.html
Copyright © 2020-2023  润新知