加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB加解密代码

发布时间:2020-12-16 23:20:26 所属栏目:大数据 来源:网络整理
导读:Function crypt( Action As String,Key As String,Src As String ) As String 'Action ' E encrypts,D decrypts, 'Key is a unique string needed to en/decrypt (either ' hardcode or setup something for the user to enter.'Src is the string to be en/

Function crypt(Action As String,Key As String,Src As String) As String

'Action
' E encrypts,D decrypts,
'Key is a unique string needed to en/decrypt (either
' hardcode or setup something for the user to enter.'Src is the string to be en/decrypted.On Error GoTo errHandler Dim count As Integer,KeyPos As Integer,KeyLen As Integer,SrcAsc As Integer Dim Dest As String,Offset As Integer,TmpSrcAsc,SrcPos As Integer KeyLen = Len(Key) If Action = "E" Then Randomize Offset = (Rnd * 10000 Mod 255) + 1 Dest = Hex$(Offset) For SrcPos = 1 To Len(Src) SrcAsc = (Asc(Mid$(Src,SrcPos,1)) + Offset) Mod 255 If KeyPos < KeyLen Then KeyPos = KeyPos + 1 Else KeyPos = 1 'Fill Dest$ with HEX representation of Encrypted field 'Hex used to keep nasties such as eof or lf from mangling stream 'Use format$ to make Hex$ return " 0" instead of "0" when the same 'values are Xor'ed together (Null) - keeps placeholder for decrypt SrcAsc = SrcAsc Xor Asc(Mid$(Key,KeyPos,1)) Dest = Dest + Format$(Hex$(SrcAsc),"@@") Offset = SrcAsc Next ElseIf Action = "D" Then Offset = Val("&H" + Left$(Src,2)) For SrcPos = 3 To Len(Src) Step 2 SrcAsc = Val("&H" + Trim(Mid$(Src,2))) If KeyPos < KeyLen Then KeyPos = KeyPos + 1 Else KeyPos = 1 TmpSrcAsc = SrcAsc Xor Asc(Mid$(Key,1)) If TmpSrcAsc <= Offset Then TmpSrcAsc = 255 + TmpSrcAsc - Offset Else TmpSrcAsc = TmpSrcAsc - Offset End If Dest = Dest + Chr(TmpSrcAsc) Offset = SrcAsc Next End If crypt = Dest Exit FunctionerrHandler: LogErrors Err.Number,Err.Description,"Module - Startup","crypt" Resume NextEnd Function

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读