PB的一些记录

断点设置在函数内,发现返回值没有,需要取消函数内断点才正常

加密--采用矩阵乘法

行列式取+_1的矩阵与逆矩阵其元素都是整数,, 可以使用matlab来找到这些矩阵

A* I   =E       A^-1 * E=I   A与A^-1 加密矩阵与其逆矩阵, I是待加密矩阵,  E是加密后的矩阵

long ENMatrix[16]={  0,     1,     21,     1,2,     1,     3,     3,4,     0,     4,     1, 3,     0,     3,     1}
long DEMatrix[16]={-1,     1,     5,    -17,-1,     2,    12,   -18, 1,    -1,    -4,     6, 0,     0,    -3,     4}
int MixArr[16]={1,3,2,6,  15,7,4,84,  10,6,3,4, ,6,7,8,5 }
int i=1
int j =0 
int s2
string s1
string ret=""
string tmp=""
string arr[16]
j=len(vstr)
if j <>16 then
    messagebox('错误','只接受16位字符')
    return ""
end if
//只接受16位密码

long srcMatrix[16]
long tagMatrix[16]
for i = 1 to j
    s1= mid(vstr,i,1)
    srcMatrix[i] = asc(s1)
next
int row
int col
for row=1 to 4
    for col=1 to 4
        tagMatrix[(row -1) * 4 + col]=& 
            ENMatrix[(row -1)*4 +1] * srcMatrix[col -1 +1] &
        +  ENMatrix[(row -1)*4 +2] * srcMatrix[col -1 +5] & 
        +  ENMatrix[(row -1)*4 +3] * srcMatrix[col -1 +9]  & 
        +  ENMatrix[(row -1)*4 +4] * srcMatrix[col -1 +13]
    next
next

for i=1 to 16
       tmp=string(tagMatrix[i])
    arr[i]=right("000" +tmp ,4)
next


for i=1 to 16
    tmp=arr[1]
    arr[1]=arr[MixArr[i]]
    arr[MixArr[i]]=tmp
next
for i=1 to 16
    ret =ret+arr[i]
next

return ret
View Code

解密

long ENMatrix[16]={  0,     11,     2,     1,0,     1,     0,     3,14,     0,     4,     1, 3,     0,     3,     1}
long DEMatrix[16]={-8,     1,     15,    -17,-1,     2,    11,   -15, 1,    -1,    -4,     6, 0,     0,    -3,     4}
int MixArr[16]={6,41,8,  15,2,4,14,  12,6,3,4, 13,7,8,5 }
int i=1
int j =0 
int s2
string s1
int arr[16]
string tmp
int tmpInt
string ret
j=len(vstr)

if j <>16*4 then
    messagebox('错误','只接受16位字符')
    return ""
end if
//只接受16位密码
for i=1 to  16
    arr[i]= integer(mid(vstr,(i -1)*4 +1,4))
next
for i=1 to 16
    tmpInt=arr[MixArr[16 -i+1]]
    arr[MixArr[16 -i+1]]=arr[1]
    arr[1]=tmpInt
next

long tagMatrix[16]
int row
int col
for row=1 to 4
    for col=1 to 4
        tagMatrix[(row -1) * 4 + col]=& 
            DEMatrix[(row -1)*4 +1] * arr[col -1 +1] &
        +  DEMatrix[(row -1)*4 +2] * arr[col -1 +5] & 
        +  DEMatrix[(row -1)*4 +3] * arr[col -1 +9]  & 
        +  DEMatrix[(row -1)*4 +4] * arr[col -1 +13]
    next
next

for i=1 to 16
    ret=ret + char(tagMatrix[i])
next
return ret
View Code

猜你喜欢

转载自www.cnblogs.com/wdfrog/p/10427383.html
今日推荐