yafu安裝使用方法以及mismatched parens解決方法


yafu用於自動整數因式分解,在RSA中,當p、q的取值差異過大或過於相近的時候,使用yafu可以快速的把n值分解出p、q值,原理是使用Fermat方法與Pollard rho方法等。

再摘錄官方的一段簡介(又懶得翻譯了)。

YAFU (with assistance from other free software) uses the most powerful modern algorithms (and implementations of them) to factor input integers in a completely automated way. The automation within YAFU is state-of-the-art, combining factorization algorithms in an intelligent and adaptive methodology that minimizes the time to find the factors of arbitrary input integers. Most algorithm implementations are multi-threaded, allowing YAFU to fully utilize multi- or many-core processors (including SNFS, GNFS, SIQS, and ECM).

YAFU is primarily a command-line driven tool. You provide the number to factor and, via screen output and log files, YAFU will provide you the factors. There is also an interactive environment similar to MATLAB or PARI/GP, where you can type commands and store results. YAFU is very customizable, through the optional use of many many command line parameters and a very capable expression interpreter.

-------------------------------------------------

1. windows安裝

https://sourceforge.net/projects/yafu/

現在最新版本是1.34版本,下載后解壓即可。

解壓后有yafu-Win32.exe和yafu-x64.exe,推薦使用64位的。

 

2. linux安裝

上面壓縮包里有一個yafu的elf文件,可以在一些linux上運行,由於是靜態編譯的,在一些系統上想要使用yafu就得重新編譯。

 

3. linux編譯安裝

參考了sherlly的文章,然后測試、整合成腳本。

apt-get update
apt-get install gcc m4 zlib1g-dev make -y

mkdir -p $HOME/src

# install gmp
cd $HOME/src
v=6.1.2
wget https://gmplib.org/download/gmp/gmp-${v}.tar.bz2
tar -jxvf gmp-${v}.tar.bz2 && mv gmp-${v} gmp && cd gmp
./configure
make && make check && make install

# install gmp-ecm
cd $HOME/src
v=6.2
wget https://gforge.inria.fr/frs/download.php/file/4663/ecm-${v}.tar.gz
tar zxvf ecm-${v}.tar.gz && mv ecm-${v} gmp-ecm && cd gmp-ecm
# replace __GMP_BITS_PER_MP_LIMB with GMP_LIMB_BITS
x='__GMP_BITS_PER_MP_LIMB';y='GMP_LIMB_BITS';sed -i "s#${x}#${y}#g" `grep ${x} -rl .`
./configure --with-gmp=/usr/local
make && make install

# install msieve
cd $HOME/src
v1=1.52
v2=152
wget http://downloads.sourceforge.net/project/msieve/msieve/Msieve%20v${v1}/msieve${v2}.tar.gz
tar zxvf msieve${v2}.tar.gz && mv msieve-${v1} msieve && cd msieve
make all

# install yafu
cd $HOME/src
git clone https://github.com/DarkenCode/yafu
cd yafu
# modify Makefile
sed -i 's#INC = -I. -Iinclude#& -Itop/aprcl#;s#gmp/include#gmp#g;s#gmp/lib/linux/x86_64#gmp/.libs#;
s#gmp-ecm/include/linux#gmp-ecm#g;s#gmp-ecm/lib/linux/x86_64#gmp-ecm/.libs#;
s#msieve/lib/linux/x86_64#msieve#;122i LIBS+= -lc -lz' Makefile
# comment
sed -i 's#printf("setting prime roots#//&#g;s#printf("medsieve#//&#g;s#printf("lpsieve#//&#g;
s#printf("scan p#//&#g;s#printf("next B#//&#g;s#printf("next roots#//&#g' factor/qs/SIQS.c
make x86_64 NFS=1

 

4. yafu使用方法

使用cmd進入yafu的解壓目錄(為了方便的話,自己可以把該目錄加入到環境變量。)

輸入yafu-x64進入命令行

最常用的命令是factor(n),將n值分解

如分解23333333333333

factor(23333333333333)

很快得到:

fac: factoring 23333333333333
fac: using pretesting plan: normal
fac: no tune info: using qs/gnfs crossover of 95 digits
div: primes less than 10000
fmt: 1000000 iterations
Total factoring time = 0.2805 seconds


***factors found***

P2 = 31
P12 = 752688172043

ans = 1

 

5. 使用yafu的時候遇到mismatched parens

這是因為在命令行里不支持過長的位數,所以我們只要把n的值從文件中去讀取即可。

查看yafu的幫助:

yafu-x64.exe help

新建一個文件pcat.txt,內容里寫上n的值,如:

966808932627497190635859236054960349099463975227350564265384373280336699853387254070662881265937565163000758606154308757944030571837175048514574473061401566330836334647176655282619268592560172726526643074499534129878217409046045533656897050117438496357231575999185527675071002803951800635220029015932007465117818739948903750200830856115668691007706836952244842719419452946259275251773298338162389930518838272704908887016474007051397194588396039111216708866214614779627566959335170676055025850932631053641576566165694121420546081043285806783239296799795655191121966377590175780618944910532816988143056757054052679968538901460893571204904394975714081055455240523895653305315517745729334114549756695334171142876080477105070409544777981602152762154610738540163796164295222810243309051503090866674634440359226192530724635477051576515179864461174911975667162597286769079380660782647952944808596310476973939156187472076952935728249061137481887589103973591082872988641958270285169650803792395556363304056290077801453980822097583574309682935697260204862756923865556397686696854239564541407185709940107806536773160263764483443859425726953142964148216209968437587044617613518058779287167853349364533716458676066734216877566181514607693882375533

注意:最后面一定要換行,不然會出現eof; done processing batchfile

然后運行命令為

yafu-x64 "factor(@)" -batchfile pcat.txt

很快得到:

***factors found***

PRP617 = 31093551302922880999883020803665536616272147022877428745314830867519351013248914244880101094365815998050115415308439610066700139164376274980650005150267949853671653233491784289493988946869396093730966325659249796545878080119206283512342980854475734097108975670778836003822789405498941374798016753689377992355122774401780930185598458240894362246194248623911382284169677595864501475308194644140602272961699230282993020507668939980205079239221924230430230318076991507619960330144745307022538024878444458717587446601559546292026245318907293584609320115374632235270795633933755350928537598242214216674496409625928997877221
PRP617 = 31093551302922880999883020803665536616272147022877428745314830867519351013248914244880101094365815998050115415308439610066700139164376274980650005150267949853671653233491784289493988946869396093730966325659249796545878080119206283512342980854475734097108975670778836003822789405498941374798016753689377992355122774401780930185598458240894362246194248623911382284169677595864501475308194644140602272961699230282993020507668939980205079239221924230430230318076991507619960330144745307022538024878444458717587446601559546292026245318907293584609320115374632235270795633933755350928537598242214216674496409625928797450473

ans = 1

注意:運行后,pcat.txt就會消失了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM