算法,不会?

kyzh 2003-12-16 12:02:20
字符串里有15位数字,我想通过这15位数字计算得到36位唯一的数字出来,代码怎么写啊?
...全文
66 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyuj 2003-12-16
  • 打赏
  • 举报
回复
用一段加密码算法不就行了比如MD5啦!
jornet 2003-12-16
  • 打赏
  • 举报
回复
建议用循环冗余校验算法加密,这个算法网上有很多源代码的
landongfang 2003-12-16
  • 打赏
  • 举报
回复
Dim a As String
Dim j As Integer

Dim c As String
Dim b() As Byte
c = ""
a = "546789908887766"
b = a
For j = 0 To UBound(b)
If (j > (UBound(b) - 18)) And (j Mod 2) = 1 Then
Else
c = c & b(j)
End If

Next
northwolves 2003-12-16
  • 打赏
  • 举报
回复
有个简单的办法,可以转化为别的进制,下面是一个转化为3进制的例子,位数不足用0补齐,结果应该是唯一的:
Private Sub Command1_Click()
MsgBox dectothird(String(15, "9"))
End Sub

Function dectothird(ByVal hugenum As String) As String ' trans hugenum to third
Do While Not Val(hugenum) < 3
dectothird = Val(Right(hugenum, 2)) Mod 3 & dectothird
hugenum = third(hugenum) 'devide hugenum by 3
Loop
dectothird = Val(hugenum) & dectothird
dectothird = Right(String(36, "0") & dectothird, 36)
End Function
Function third(ByVal x As String) As String 'get third of x
Dim temp As String, result() As String
temp = x
Dim i As Long
ReDim result(1 To Len(temp)) As String
result(1) = Mid(temp, 1, 1) \ 3
Mid(temp, 1, 1) = Val(Mid(temp, 1, 1) Mod 3)
For i = 2 To Len(x)
result(i) = (Val(Mid(temp, i, 1)) + Val(Mid(temp, i - 1, 1)) * 10) \ 3
Mid(temp, i, 1) = (Val(Mid(temp, i, 1)) + Val(Mid(temp, i - 1, 1)) * 10) Mod 3
Next
third = Join(result, "")
If Left(thirdh, 1) = "0" Then third = Right(third, Len(third) - 1) ' no zero ahead
Erase result
End Function
kmzs 2003-12-16
  • 打赏
  • 举报
回复
呵呵
jian_aa 2003-12-16
  • 打赏
  • 举报
回复
up

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧