导航:首页 > 文档加密 > 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怎么加密符串相关的资料

热点内容
bs刷装备建立后文件夹没有 浏览:77
找漫画看应该下载什么app 浏览:182
如何在vps上搭建自己的代理服务器 浏览:744
nginxphp端口 浏览:403
内脏pdf 浏览:152
怎么看云服务器架构 浏览:85
我的世界国际服为什么登不进服务器 浏览:996
微盟程序员老婆 浏览:930
intellij创建java 浏览:110
java连接odbc 浏览:38
启动修复无法修复电脑命令提示符 浏览:359
手机编程是什么 浏览:98
山东移动程序员 浏览:163
苏州java程序员培训学校 浏览:479
单片机液晶驱动 浏览:856
魔拆app里能拆到什么 浏览:132
新预算法的立法理念 浏览:144
wdcpphp的路径 浏览:136
单片机p0口电阻 浏览:927
浏览器中调短信文件夹 浏览:595