某字符串加密算法,規(guī)則如下: (1)根據(jù)字符串長(zhǎng)度構(gòu)建一個(gè)最小的n*n矩陣,將字符串中每個(gè)字符從左到右,自上而下順序填入矩陣,不足部分用字符“*”代替; (2)將矩陣轉(zhuǎn)置(行列對(duì)換),然后將奇數(shù)行字母內(nèi)碼加上1,偶數(shù)行字母內(nèi)碼減1,字符為a、z或A、Z時(shí)做循環(huán)處理。比如,字符a減1為z;字符Z加1為A。 (3)按從左到右,從上而下依次取出字符,形成新的字符串。如圖a為字符串“Go to the zoo.”的加密過(guò)程。編寫(xiě)VB程序,在文本框Text1中輸入字符串,點(diǎn)擊“加密”按鈕,在文本框Text2中輸出加密后的字符串。程序運(yùn)行結(jié)果如圖b所示。
。 (2)實(shí)現(xiàn)上述功能的 VB 程序如下,請(qǐng)?jiān)跈M線處填入合適的代碼 Dim a(1 To 100)As String,b(1 To 100)As String,n As Integer Private Sub Command1_Click
加密
加密
Dim s1 As String,s2 As String,i As Integer,j As Integer,m As Single s1=Text1.Text m=Sqr(Len(s1)) If m>Int(m) Then n=Int(m)+1 Else n=m For i=1 To n*n If i<=Len(s1)Then a(i)=Mid(s1,i,1)Else a(i)=“*“ Next i For i=1 To n For j=1 To n b((i-1)*n+j)=
a((j-1)*n+i)
a((j-1)*n+i)
‘將矩陣轉(zhuǎn)置 b((i-1)*n+j)=jm(i,j)‘內(nèi)碼變換 Next j Next i s2=““ For i=1 To n*n s2=s2 & b(i) Next i Text2.Text=s2 End Sub Function jm(x As Integer,y As Integer) As String Dim s As String s=b((x-1)*n+y) If s<=“Z“And s>=“A“Or s<=“z“And s>=“a“Then If x Mod 2<>0 Then If s<>“Z“And s<>“z“Then s=Chr(Asc(s)+1) Else s=Chr(Asc(s)-25) End If Else If s<>“a“And s<>“A“Then s=Chr(Asc(s)-1) Else s=