Installation and simple use of libnum Library
When looking at the title, I found the libnum library and thought it was all right. Mark came down and saved it for later use.
0x00
Libnum library is a function library about various mathematical operations, which contains functions such as common maths, modular, modular squre roots, primes, factorization, ECC, converting, stuff and so on, which makes the calculation very simple.
0x01 installation
Linux:
Git clone https://github.com/hellman/libnumcd libnumpython setup.py install
Windows: download and extract it
Converting commonly used in cd libnumpython setup.py install0x02
Conversion between numeric (whether hexadecimal or decimal) and string:
Import libnums= "flag {aaa}" print (libnum.s2n (s)) import libnumn=0x1889377532526823825789 print (libnum.n2s (n))
This conversion does not care whether the number of hexadecimal digits is even.
Conversion between binary and string:
The number of digits in import libnumb=''0100110001111001011100100110100101100011'' print (libnum.b2s (b)) binary is preferably a multiple of 8 import libnums='Lyric' print (libnum.s2b (s)) 0x03 prime-factor decomposition
Generate prime numbers:
Libnum.generate_prime (1024) ```Factorization:
Libnum.factorize (1024) ```
0x04 other
A script used to solve a problem in a ctf
#!coding:utf-8#RSAimport libnump = 153342497773165720646471265753416937042378585974980600696228054280777067742118708748260148517704664270966750151230879697775745552153863038444052153549264336387543725044459125347571130674447630098572217293190874462747269265287826289527205379087607586543990164027856167617915226681078528645859423680436167557483q = 129436166908331611554181128183182589454341960422674433223367230133752416435382709963204302422852744109315802741839344452057748805269289759475931297256986800620920742486276489445279916851138781600867108041340752127975698302831477903370939720026728065273734373673806527712975351406042878379903498709089420733911n = p * qe = 65537c = 3936037472808777071308929516154413904323194935340248548327659414834313812796990403988095925642368079268517801058041656316181783492880322278956562595000260504254255037928037412478862828849501974686520351939250369196179274580006017942557434135384292957158484997604383679828898427028204052111920452543131945953240230799711698405726536262211948501121455918845580494839990978306064590105574542739676508765285583405238287804427122294772381588739840326134102495086948522002204793929245624099798045204501372180048163169180023176545149820275841071238390132249159995705693884766122963689536408510312667760860122892135226523829phi = (p-1) * (q-1)d = libnum.modular.invmod(e, phi)m = libnum.n2s(pow(c, d, n)) print(m)