导航:首页 > 文档加密 > vb怎么加密符串

vb怎么加密符串

发布时间:2022-02-28 17:16:15

Ⅰ vb 根据密码加密字符串

是随机数方式,不是md5,一般用也不错
放到标准模块里,调用那加密和解密的函数就行了

'加密解密字符串

Option Explicit

' Encipher the text using the pasword.加密
Public Function cipher(ByVal password As String, ByVal from_text As String)
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1

Dim offset As Long
Dim str_len As Integer
Dim i As Integer
Dim ch As Integer
Dim to_text As String

' Initialize the random number generator.
offset = NumericPassword(password)
Rnd -1
Randomize offset

' Encipher the string.
str_len = Len(from_text)
For i = 1 To str_len
ch = Asc(Mid$(from_text, 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
to_text = to_text & Chr$(ch)
End If
Next i
cipher = to_text
End Function
' Encipher the text using the pasword.解密
Public Function Decipher(ByVal password As String, ByVal from_text As String)
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1

Dim offset As Long
Dim str_len As Integer
Dim i As Integer
Dim ch As Integer
Dim to_text As String

' Initialize the random number generator.
offset = NumericPassword(password)
Rnd -1
Randomize offset

' Encipher the string.
str_len = Len(from_text)
For i = 1 To str_len
ch = Asc(Mid$(from_text, 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)
If ch < 0 Then ch = ch + NUM_ASC
ch = ch + MIN_ASC
to_text = to_text & Chr$(ch)
End If
Next i
Decipher = to_text
End Function

' Translate a password into an offset value.
Private Function NumericPassword(ByVal password As String) As Long
Dim value As Long
Dim ch As Long
Dim shift1 As Long
Dim shift2 As Long
Dim i As Integer
Dim str_len As Integer

str_len = Len(password)
For i = 1 To str_len
' Add the next letter.
ch = Asc(Mid$(password, i, 1))
value = value Xor (ch * 2 ^ shift1)
value = value Xor (ch * 2 ^ shift2)

' Change the shift offsets.
shift1 = (shift1 + 7) Mod 19
shift2 = (shift2 + 13) Mod 23
Next i
NumericPassword = value
End Function

Ⅱ vb 字母 加密字符串

PrivateSubCommand1_Click()'加密
DimpAsString,sAsString,tAsString
DimiAsInteger,kAsInteger
p=""
s=Text1.Text
Fori=1ToLen(s)
k=InStr(p,Mid(s,i,1))
Ifk=0Then
MsgBox"数据有误"
ExitSub
Else
t=t&Mid(p,((k+4)Mod52)+1,1)
EndIf
Next
Text2.Text=t
Text1.Text=""
EndSub

PrivateSubCommand2_Click()'解密
DimpAsString,sAsString,tAsString
DimiAsInteger,kAsInteger
p=""
s=Text2.Text
Fori=1ToLen(s)
k=InStr(p,Mid(s,i,1))
Ifk=0Then
MsgBox"数据有误"
ExitSub
Else
t=t&Mid(p,((k+46)Mod52)+1,1)
EndIf
Next
Text1.Text=t
Text2.Text=""
EndSub

以上代码用到四个控件:Text1放加密前的数据,Text2放加密后的数据,Command1点击加密,Command2点击解密

Ⅲ VB编写程序,实现对任意字符串的加密和解密操作。

http://..com/question/215182971.html
LZ可以去看看、
或者在BAIDU里找找BASE 64的加密解密,

Ⅳ VB 实现字符串加密 解密

What???

不懂你说什么..

加密比较常用的是异或运算,即把每个字符的ASCII码进行异或运算

Ⅳ vb如何加密字符串

是随机数方式,不是md5,一般用也不错
放到标准模块里,调用那加密和解密的函数就行了

'加密解密字符串

Option Explicit

' Encipher the text using the pasword.加密
Public Function cipher(ByVal password As String, ByVal from_text As String)
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1

Dim offset As Long
Dim str_len As Integer
Dim i As Integer
Dim ch As Integer
Dim to_text As String

' Initialize the random number generator.
offset = NumericPassword(password)
Rnd -1
Randomize offset

' Encipher the string.
str_len = Len(from_text)
For i = 1 To str_len
ch = Asc(Mid$(from_text, 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
to_text = to_text & Chr$(ch)
End If
Next i
cipher = to_text
End Function
' Encipher the text using the pasword.解密
Public Function Decipher(ByVal password As String, ByVal from_text As String)
Const MIN_ASC = 32 ' Space.
Const MAX_ASC = 126 ' ~.
Const NUM_ASC = MAX_ASC - MIN_ASC + 1

Dim offset As Long
Dim str_len As Integer
Dim i As Integer
Dim ch As Integer
Dim to_text As String

' Initialize the random number generator.
offset = NumericPassword(password)
Rnd -1
Randomize offset

' Encipher the string.
str_len = Len(from_text)
For i = 1 To str_len
ch = Asc(Mid$(from_text, 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)
If ch < 0 Then ch = ch + NUM_ASC
ch = ch + MIN_ASC
to_text = to_text & Chr$(ch)
End If
Next i
Decipher = to_text
End Function

' Translate a password into an offset value.
Private Function NumericPassword(ByVal password As String) As Long
Dim value As Long
Dim ch As Long
Dim shift1 As Long
Dim shift2 As Long
Dim i As Integer
Dim str_len As Integer

str_len = Len(password)
For i = 1 To str_len
' Add the next letter.
ch = Asc(Mid$(password, i, 1))
value = value Xor (ch * 2 ^ shift1)
value = value Xor (ch * 2 ^ shift2)

' Change the shift offsets.
shift1 = (shift1 + 7) Mod 19
shift2 = (shift2 + 13) Mod 23
Next i
NumericPassword = value
End Function

Ⅵ 用VB怎么样实现MD5加密字符串

直接调用算法对字符串加密就OK了

Ⅶ vb 加密字符串的方法

PrivateSubCommand1_Click()'加密
Dimb()AsByte,iAsLong
Open"d:1.txt"ForBinaryAs#1
b=InputB(LOF(1),#1)
Close#1
Randomize
Fori=0ToUBound(b)-1
b(i)=b(i)Xorb(i+1)
Next
b(i)=b(i)Xor93
Open"d:2.txt"ForBinaryAs#1
Put#1,,b
Close#1
MsgBox"1.txt已加密为2.txt"
EndSub

PrivateSubCommand2_Click()'解密
Dimb()AsByte,iAsLong
Open"d:2.txt"ForBinaryAs#1
b=InputB(LOF(1),#1)
Close#1
Randomize
b(UBound(b))=b(UBound(b))Xor93
Fori=UBound(b)-1To0Step-1
b(i)=b(i)Xorb(i+1)
Next
Open"d:3.txt"ForBinaryAs#1
Put#1,,b
Close#1
MsgBox"2.txt已解密为3.txt"
EndSub

1.txt加密后存为2.txt

2.txt解密后存为3.txt

请注意,这个程序是可以加密解密任何文件的(包括exe可执行文件),不单单是文本文件。

Ⅷ VB ascll 字符串加密

Option Explicit

Private Sub Command1_Click()
Dim i As Integer
Text2 = ""
For i = 1 To Len(Text1)
Text2 = Text2 + Chr(Asc(Mid(Text1, i, 1)) + 1)
Next i
End Sub

这里面还要考虑到ASCII码的最大值的问题,呵呵,自己解决吧。

Ⅸ Vb 简单字符串加密优化

PrivateSub加密_Click()
Dimb()AsByte,iAsLong
b=StrConv(Text1.Text,vbFromUnicode)
Fori=0ToUBound(b)
b(i)=b(i)Xor50
Next
Text2.Text=StrConv(b,vbUnicode)
EndSub

PrivateSub解密_Click()
Dimb()AsByte,iAsLong
b=StrConv(Text2.Text,vbFromUnicode)
Fori=0ToUBound(b)
b(i)=b(i)Xor50
Next
Text1.Text=StrConv(b,vbUnicode)
EndSub


把文本框转为字节数组,然后对这个字节数组进行加密或解密处理,最后再把字节数组赋值给文本框即可。

另外,你可以发现,加密和解密其实是同一个算法!这就是Xor(异或运算)的神奇之处!

Ⅹ vb中如何对字符串进行加密和解密(有汉字的)

函数没问题, 你的调用方法有问题:

Private Sub Form_Load()
Dim s As String
s = UserCode("1234中文")
Debug.Print s '这里显示出来的就是一串?
Debug.Print UserDeCode(s) '这里显示出来的是加密前的原文了
End
End Sub

阅读全文

与vb怎么加密符串相关的资料

热点内容
c编译器上的帧指针 浏览:741
HY单片机 浏览:584
php伪ip 浏览:517
继电器单片机连接 浏览:827
php设置referer 浏览:639
接收到的文件夹怎么重命名 浏览:774
pdf发票修改 浏览:992
绝对服从命令游戏有h吗 浏览:168
阿里云9块服务器 浏览:155
php查询结果分页 浏览:453
python爬虫的可靠性 浏览:503
转不了pdf 浏览:68
bat编译成exe怎么看源码 浏览:166
服务器常用服务器地址 浏览:603
腾讯云服务器到底安不安全 浏览:165
缓解压力做法英语 浏览:654
编译器遵循的规则 浏览:20
深度优先遍历递归算法 浏览:530
服务器上的ip地址是什么意思 浏览:272
双单片机串行通信 浏览:468