導航:首頁 > 文檔加密 > 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怎麼加密符串相關的資料

熱點內容
自動解壓失敗叫我聯系客服 瀏覽:482
易語言新手源碼 瀏覽:456
oa伺服器必須有固定ip地址 瀏覽:42
傳奇源碼分析是什麼 瀏覽:267
解放壓縮機支架 瀏覽:255
程序員禿頂搞笑相遇 瀏覽:6
IBM手機app商店叫什麼名字 瀏覽:834
jpeg壓縮質量 瀏覽:774
雲伺服器評測對比 瀏覽:145
java日期轉string 瀏覽:221
openfire源碼編譯 瀏覽:897
在線小工具箱引流網站源碼 瀏覽:337
非科班程序員自學 瀏覽:801
壓縮泡沫鞋底底材 瀏覽:219
程序員職場第一課2正確的溝通 瀏覽:679
遇到不合法app應該怎麼辦 瀏覽:91
匯編程序編譯後的文件 瀏覽:80
大智慧均線源碼 瀏覽:374
單片機排阻的作用 瀏覽:216
滴滴金融app被下架如何還款 瀏覽:212