發新話題
打印

用maxima學密碼學-Lattice Reduction應用1

推到噗浪
推到臉書

用maxima學密碼學-Lattice Reduction應用1

maxima內建LLL指令但執行結果會出現錯誤。

要先載入lll.lisp才能使用latticereduce指令
(%i1) load("lll.lisp");
(%o1) C:\maxima-5.41.0\share\maxima\5.41.0\share\contrib\lll.lisp

https://math.pro/db/viewthread.php?tid=1876&page=1#pid10232的範例
執行結果正確

(%i2) latticereduce([[31,59],[37,70]]);
(%o2) \( [[1,4],[3,-1]] \)

https://math.pro/db/viewthread.php?tid=1876&page=1#pid10232的範例
執行結果正確

(%i3) latticereduce([[47,9],[26,4]]);
(%o3) \( [[5,-1],[-1,-9]] \)

https://math.pro/db/viewthread.php?tid=1876&page=1#pid10892的範例
執行結果錯誤,應該是\([[0,1,0],[1,0,1],[-1,0,2]]\)

(%i4) latticereduce([[1,1,1],[-1,0,2],[3,5,6]]);
(%o4) \( [[0,1,0],[1,0,1],[-2,0,1]] \)

https://math.pro/db/viewthread.php?tid=1876&page=1#pid10831的範例
執行結果正確

(%i5) latticereduce([[1,1,7,2],[9,8,4,6],[1,8,5,7],[2,3,1,1]]);
(%o5) \( [[2,3,1,1],[3,-1,1,3],[-2,2,6,-1],[-4,1,-4,3]] \)

https://math.pro/db/viewthread.php?tid=1876&page=1#pid10831的範例
latticereduce只能處理方陣,行數與列數不同會出現錯誤

(%i6)
latticereduce([[4,9,3,-5,-5,-1,7,-1,-5],
                   [-2,-8,-7,-1,-3,6,-3,9,8],
                   [1,-3,-2,3,9,7,2,7,-2],
                   [-5,6,4,-2,-2,-7,-2,-9,1],
                   [1,-2,-2,7,7,-3,-9,-5,-4],
                   [7,1,-4,3,-2,9,9,7,6]]);

Maxima encountered a Lisp error:
MAKE-ARRAY: (4 9 3 -5 -5 -1 7 -1 -5) is of incorrect length
Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.




放棄使用maxima內建的LLL,改用自己寫的LLL()副程式
請下載LLL.zip,解壓縮後將LLL.mac放到C:\maxima-5.41.0\share\maxima\5.41.0目錄下


要先載入LLL.mac才能使用LLL指令
(%i1) load("LLL.mac");
(%o1) C:\maxima-5.41.0\share\maxima\5.41.0\LLL.mac

(%i2)
LLL(matrix([31,59],
                [37,70]));

0 errors, 0 warnings
(%o2) \( \left[ \matrix{3&-1 \cr 1&4}\right] \)

(%i3)
LLL(matrix([47,9],
                [26,4]));

(%o3) \( \left[ \matrix{5&-1 \cr -1&-9}\right] \)

(%i4)
LLL(matrix([1,1,1],
                [-1,0,2],
                [3,5,6]));

(%o4) \( \left[ \matrix{0&1&0 \cr 1&0&1 \cr -1&0&2} \right] \)

(%i5)
LLL(matrix([1,1,7,2],
                [9,8,4,6],
                [1,8,5,7],
                [2,3,1,1]));

(%o5) \( \left[ \matrix{2&3&1&1 \cr 3&-1&1&3 \cr -2&2&6&-1 \cr -4&1&-4&3} \right] \)

(%i6)
LLL(matrix([4,9,3,-5,-5,-1,7,-1,-5],
                [-2,-8,-7,-1,-3,6,-3,9,8],
                [1,-3,-2,3,9,7,2,7,-2],
                [-5,6,4,-2,-2,-7,-2,-9,1],
                [1,-2,-2,7,7,-3,-9,-5,-4],
                [7,1,-4,3,-2,9,9,7,6]));

(%o6) \( \left[ \matrix{-4 & 3 & 2 & 1 & 7 & 0 & 0 & -2 & -1 \cr 3 & -1 & -6 & 1 & -1 & 2 & -5 & 3 & -1 \cr -2 & 4 & -2 & -5 & -1 & 5 & 4 & 6 & 2 \cr 3 & 11 & -1 & -3 & 1 & 1 & 2 & 0 & -7 \cr 2 & -5 & 2 & 1 & 3 & 5 & 7 & 6 & 0 \cr 1 & 9 & -4 & 3 & 2 & 4 & 2 & -1 & 5} \right] \)

TOP

發新話題