中文字段如何加密?

twinking 2003-01-14 10:11:26
请教各位
对包含中英文数字等的字段
如何加密和解密呢?
...全文
3 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pigpag 2003-07-25
一般来说,你把它们灌到Byte()数组里面加密比较好。Byte()会将Unicode进行拆分。
回复
since1990 2003-07-25


经典加密算法在VB中的实现(3)- RC4

public sub main()
dim key as string
for i = 1 to 16
randomize
key = key & chr(rnd * 255)
next i
msgbox rc4(rc4("welcome to plindge studio!", key), key)
end sub
public function rc4(inp as string, key as string) as string
dim s(0 to 255) as byte, k(0 to 255) as byte, i as long
dim j as long, temp as byte, y as byte, t as long, x as long
dim outp as string

for i = 0 to 255
s(i) = i
next

j = 1
for i = 0 to 255
if j > len(key) then j = 1
k(i) = asc(mid(key, j, 1))
j = j + 1
next i

j = 0
for i = 0 to 255
j = (j + s(i) + k(i)) mod 256
temp = s(i)
s(i) = s(j)
s(j) = temp
next i

i = 0
j = 0
for x = 1 to len(inp)
i = (i + 1) mod 256
j = (j + s(i)) mod 256
temp = s(i)
s(i) = s(j)
s(j) = temp
t = (s(i) + (s(j) mod 256)) mod 256
y = s(t)

outp = outp & chr(asc(mid(inp, x, 1)) xor y)
next
rc4 = outp
end function




一个简单实用的 vb 加密/解密算法

Function UserCode(password As String) As String
'用户口令加密
Dim il_bit, il_x, il_y, il_z, il_len, i As Long
Dim is_out As String
il_len = Len(password)
il_x = 0
il_y = 0
is_out = ""
For i = 1 To il_len
il_bit = AscW(Mid(password, i, 1)) 'W系列支持unicode

il_y = (il_bit * 13 Mod 256) + il_x
is_out = is_out & ChrW(Fix(il_y)) '取整 int和fix区别: fix修正负数
il_x = il_bit * 13 / 256
Next
is_out = is_out & ChrW(Fix(il_x))

password = is_out
il_len = Len(password)
il_x = 0
il_y = 0
is_out = ""
For i = 1 To il_len
il_bit = AscW(Mid(password, i, 1))
'取前4位值
il_y = il_bit / 16 + 64
is_out = is_out & ChrW(Fix(il_y))
'取后4位值
il_y = (il_bit Mod 16) + 64
is_out = is_out & ChrW(Fix(il_y))
Next
UserCode = is_out
End Function
Function UserDeCode(password As String) As String
'口令解密
Dim is_out As String
Dim il_x, il_y, il_len, i, il_bit As Long

il_len = Len(password)
il_x = 0
il_y = 0
is_out = ""
For i = 1 To il_len Step 2
il_bit = AscW(Mid(password, i, 1))
'取前4位值
il_y = (il_bit - 64) * 16
'取后4位值
'dd = AscW(Mid(password, i + 1, 1)) - 64
il_y = il_y + AscW(Mid(password, i + 1, 1)) - 64
is_out = is_out & ChrW(il_y)
Next

il_x = 0
il_y = 0
password = is_out
is_out = ""

il_len = Len(password)
il_x = AscW(Mid(password, il_len, 1))

For i = (il_len - 1) To 1 Step -1
il_y = il_x * 256 + AscW(Mid(password, i, 1))
il_x = il_y Mod 13
is_out = ChrW(Fix(il_y / 13)) & is_out
Next
UserDeCode = is_out
End Function

回复
since1990 2003-07-25
http://www.csdn.net/Develop/list_article.asp?author=jlum99

经典加密算法在VB中的实现(4)- DES (jlum99收藏) Visual Basic 2267 2001-6-17

经典加密算法在VB中的实现(3)- RC4 (jlum99收藏) Visual Basic 1638 2001-6-17

经典加密算法在VB中的实现(2)- MD5 (jlum99收藏) Visual Basic 1978 2001-6-17

经典加密算法在VB中的实现(1)- Base64 (jlum99收藏)

回复
liu584 2003-05-19
中英文有区别吗?我的怎么没有这个问题。
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7451

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告