實(shí)現(xiàn)上述算法的VB程序如下,但程序中加框處有誤,請(qǐng)改正. Dim a(1To 100)As Integer Const code=“0123456789ABCDEF“ Const n=100 Private Sub Form_Load ( ?。噪S機(jī)數(shù)模擬讀取原始數(shù)據(jù) s=““ Randomize For i=1To n a(i)=Int(Rnd*16) Text1.Text=Text1.Text+ ① Next i End Sub Private Sub Command1_Click ( ?。?br />For i=1To n t=t+HtoB(a(i)) Next i For j=1To n*4Step 8'每8位一組,取前6個(gè)字符 s=s+Mid(t,j,6) Next j For i=1To 4*(n-1)Step 4'每4位一組轉(zhuǎn)為十六進(jìn)制顯示 Text2.Text=Text2.Text+BtoH(Mid(s,i,4)) Next i End Sub Function HtoB(x As Integer) As String'十六進(jìn)制轉(zhuǎn)為二進(jìn)制函數(shù) t=““ m=0 Do While ② r=x Mod 2 m=m+1 t=Trim(r)+t'trim ( )用于刪除前導(dǎo)空格 x=x\2 Loop HtoB=Mid(“0000“,1,4-m)+t End Function Function BtoH(y As String) As String'二進(jìn)制轉(zhuǎn)為十六進(jìn)制函數(shù) t1=Val(Mid(y,4,1)) t2=Val(Mid(y,3,1)) t3=Val(Mid(y,2,1)) t4=Val(Mid(y,1,1)) s=t1+t2*2+t3*4+t4*8 BtoH=Mid(code,s+1,1) End Function.
.(填數(shù)字序號(hào)) ①H2?N64Aj②[26wv9,Q③$14G/uv④zX}rb!T&}d2 (2)請(qǐng)?jiān)跈M線處填入合適的代碼. Private Sub Command1_Click ( ?。?br />Dim t As Integer Dim a(1To 4)As Integer flag=True n=0 pwd=““ Randomize Do While flag t=
①'隨機(jī)生成33-126的ASCII碼 pwd=pwd+Chr(t)
② s=0 For i=1To 4 s=s+a(i) Next i n=n+1 If n>=6And s=4Then
③ Loop Text1.Text=pwd End Sub
‘獲取字符類型:1-小寫字母,2-大寫字母,3-阿拉伯?dāng)?shù)字,4-符號(hào) Function check(x As Integer) As Integer If x>=97And x<=122Then check=1 ElseIf x>=65And x<=90Then check=2 ElseIf x>=48And x<=57Then check=3 Else check=4 End If End Function.