·将字符串(均为大写字符)s依次转换为相对应的数值(字符A~Z对应数值1~26);
·转换后的数值以K个数据为一段,将n个待处理的数据依次分割成若干段(最后一段不足部分用0来补充);
·每一段中K个数据与K*K转置矩阵进行乘法运算;
·将乘法运算得到的每一个结果值除以26求余数,依次转换成相应字符(数值1~26对应字符A~Z),最后按原始字符串长度输出。
乘法运算规则如下:
第i个元素c(i) =第j个元素a(j) * 转置矩阵第i行第j个元素b(t)的乘积之和(其中j = 1 , 2 …K)
例如:字符串s = PYTHON,区块大小K = 4的转置过程如下:
Private Sub Command1_Click()
Dim a(1 To 100) As Integer ‘存储字符串,长度不超过100个字符
Dim b(1 To 100) As Integer ‘存储转置矩阵,长度不超过10*10
Dim c(1 To 100) As Long
Dim s As String, tmp As String
Dim k As Integer, t As Integer, i As Integer, j As Integer
Dim n As Integer, m As Integer, lens As Integer
s = Text1.Text ‘在Text1中输入原始字符串
k = Val(Text2.Text) ‘在Text2中输入区块大小K
Randomize
For i = 1 To k ^ 2
b(i) = Int(Rnd * 9) + 1
tmp = tmp + Str(b(i))
If i Mod k = 0 Then
List2.AddItem tmp
tmp = ""
End If
Next i
lens = Len(s): n = lens
For i = 1 To n
tmp = Mid(s, i, 1)
List1.AddItem Str(a(i))
Next i
Do While n Mod k <> 0
n = n + 1
a(n) = 0
List1.AddItem Str(a(n))
Loop
For i = 1 To n
m = (i -1) Mod k + 1
t = 1
For j =
c(i) = a(j) * b((m -1)* k + t) + c(i)
t = t + 1
Next j
Next i
For i = 1 To n
List3.AddItem Str(c(i))
Next i
s = ""
For i = 1 To lens
s = s + Chr(t + 64)
Next i
Text3.Text = s ‘在Text3中输出转置后的字符串
End Sub