博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Plaintext Encryption - 明文加密P.E.
阅读量:6038 次
发布时间:2019-06-20

本文共 4266 字,大约阅读时间需要 14 分钟。

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

好吧,这些都不懂。

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

对于加密:

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

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

· 取字符的高字节

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

对于解密:

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

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

· 取字符的高字节

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

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

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

加密 (Encryption):

Private Function Encrypt(ByVal StrSource As String) As String    '加密Dim BLowData As ByteDim BHigData As ByteDim SHigData As ByteDim i As LongDim k As IntegerDim StrEncrypt As StringDim StrChar As StringDim KeyTemp As StringDim 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 & StrEncryptEnd Function
解密(Decryption):

Private Function Decrypt(ByVal StrSource As String) As String     '解密Dim BLowData As ByteDim BHigData As ByteDim i As LongDim k As IntegerDim StrDecrypt As StringDim StrChar As StringDim KeyTemp As StringDim Key1 As ByteKeyTemp = 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 iDecrypt = StrDecryptEnd Function

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

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

所以:

Option Explicit'Copyright (c) 2014,烟台大学计算机学院'All right reserved.'作者:邵帅'文件:工程1.vsp'完成时间:2015年2月26日'版本号:v1.0.1Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Declare Function ReleaseCapture Lib "user32" () As LongPrivate Const WM_SYSCOMMAND = &H112Private Const SC_MOVE = &HF010&Private Const HTCAPTIO = 2Private Function Encrypt(ByVal StrSource As String) As String    '加密Dim BLowData As ByteDim BHigData As ByteDim SHigData As ByteDim i As LongDim k As IntegerDim StrEncrypt As StringDim StrChar As StringDim KeyTemp As StringDim 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 & StrEncryptEnd FunctionPrivate Function Decrypt(ByVal StrSource As String) As String     '解密Dim BLowData As ByteDim BHigData As ByteDim i As LongDim k As IntegerDim StrDecrypt As StringDim StrChar As StringDim KeyTemp As StringDim Key1 As ByteKeyTemp = 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 iDecrypt = StrDecryptEnd FunctionPrivate Sub clearl_Click()jiamit.Text = ""jiemit.Text = ""End SubPrivate Sub close_Click()EndEnd SubPrivate Sub copyl_Click()Clipboard.ClearClipboard.SetText (jiemit.Text)End SubPrivate Sub Image1_Click()End SubPrivate Sub jiamil_Click()jiemit.Text = Encrypt(jiamit.Text)End SubPrivate Sub jiemil_Click()jiemit.Text = Decrypt(jiemit.Text)End SubPrivate 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 SubPrivate Sub mini_Click()If Me.WindowState = 0 Then  Me.WindowState = 1End IfEnd Sub
好吧,顺便写了一个UI,纯英文界面,高大上有木有,还能学习英文,因为写了这段代码,我知道了加密和解密的英文写法。

      

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

下载:

@ Mayuko

转载于:https://www.cnblogs.com/mayuko/p/4567549.html

你可能感兴趣的文章
Google Chrome开发者工具
查看>>
第一阶段冲刺报告(一)
查看>>
使用crontab调度任务
查看>>
【转载】SQL经验小记
查看>>
zookeeper集群搭建 docker+zk集群搭建
查看>>
Vue2.5笔记:Vue的实例与生命周期
查看>>
论JVM爆炸的几种姿势及自救方法
查看>>
联合体、结构体简析
查看>>
使用throw让服务器端与客户端进行数据交互[Java]
查看>>
java反射与代理
查看>>
深度分析Java的ClassLoader机制(源码级别)
查看>>
微服务架构选Java还是选Go - 多用户负载测试
查看>>
我的友情链接
查看>>
Javascript中的异步如何实现回调
查看>>
halcon算子介绍
查看>>
挖掘你不知道的windowsxp中的带宽潜能
查看>>
Software Engineering 招聘要求
查看>>
【转载】InstallAnyWhere自动化制作安装包的知识
查看>>
69、iSCSI共享存储配置实战
查看>>
文本编程
查看>>