Giter VIP home page Giter VIP logo

number-theory-calculator's Introduction

信息安全中的数论专用计算平台

需要实现的功能

  1. 欧几里得算法和逆元

    $$ \begin{aligned} {8656} &= {1} \times {7780} + {876} \{7780} &= {8} \times {876} + {772} \{876} &= {1} \times {772} + {104} \{772} &= {7} \times {104} + {44} \{104} &= {2} \times {44} + {16} \{44} &= {2} \times {16} + {12} \{16} &= {1} \times {12} + {4} \{12} &= {3} \times {4} + {0} \ \end{aligned} $$ $$ \begin{aligned} {4} &= ({1}) \times {16} + ({-1}) \times {12} \ &= ({1}) \times {16} + ({-1}) \times ({44} - ({2}) \times {16}) \ &= ({-1}) \times {44} + ({3}) \times {16} \ &= ({-1}) \times {44} + ({3}) \times ({104} - ({2}) \times {44}) \ &= ({3}) \times {104} + ({-7}) \times {44} \ &= ({3}) \times {104} + ({-7}) \times ({772} - ({7}) \times {104}) \ &= ({-7}) \times {772} + ({52}) \times {104} \ &= ({-7}) \times {772} + ({52}) \times ({876} - ({1}) \times {772}) \ &= ({52}) \times {876} + ({-59}) \times {772} \ &= ({52}) \times {876} + ({-59}) \times ({7780} - ({8}) \times {876}) \ &= ({-59}) \times {7780} + ({524}) \times {876} \ &= ({-59}) \times {7780} + ({524}) \times ({8656} - ({1}) \times {7780}) \ &= ({524}) \times {8656} + ({-583}) \times {7780} \ \end{aligned} $$

  2. 模大数幂乘

    $$ \begin{aligned} {23}^{105} ;{mod}; {31}&\equiv ;{1}{23} * {23}^{104} ;{mod}; {31}\&\equiv ;{23}{23}^{104} ;{mod}; {31}\&\equiv ;{23}({23} ^ {2})^{52} ;{mod}; {31}\&\equiv ;{23}{2}^{52} ;{mod}; {31}\&\equiv ;{23}({2} ^ {2})^{26} ;{mod}; {31}\&\equiv ;{23}{4}^{26} ;{mod}; {31}\&\equiv ;{23}({4} ^ {2})^{13} ;{mod}; {31}\&\equiv ;{23}{16}^{13} ;{mod}; {31}\&\equiv ;{23}{16} * {16}^{12} ;{mod}; {31}\&\equiv ;{27}{16}^{12} ;{mod}; {31}\&\equiv ;{27}({16} ^ {2})^{6} ;{mod}; {31}\&\equiv ;{27}{8}^{6} ;{mod}; {31}\&\equiv ;{27}({8} ^ {2})^{3} ;{mod}; {31}\&\equiv ;{27}{2}^{3} ;{mod}; {31}\&\equiv ;{27}{2} * {2}^{2} ;{mod}; {31}\&\equiv ;{23}{2}^{2} ;{mod}; {31}\&\equiv ;{23}({2} ^ {2})^{1} ;{mod}; {31}\&\equiv ;{23}{4}^{1} ;{mod}; {31}\&\equiv ; {30} ;{mod}; {31}\\end{aligned} $$

  3. Jacobi和Legendre符号

    $$ \begin{aligned} (\frac{2314252112}{127384689113421}) &= (1) \times (\frac{2314252112}{127384689113421}) \ &= (1) \times {(-1)^{\frac{{127384689113421}^{2}}{8}}}^{2} \times (\frac{578563028}{127384689113421}) \ &= (1) \times (\frac{578563028}{127384689113421}) \ &= (1) \times {(-1)^{\frac{{127384689113421}^{2}}{8}}}^{2} \times (\frac{144640757}{127384689113421}) \ &= (1) \times (\frac{144640757}{127384689113421}) \ &= (1) \times (-1)^{{\frac{127384689113421-1}{2}}\cdot{\frac{144640757-1}{2}}} \times (\frac{127384689113421}{144640757}) \ &= (1) \times (\frac{8345792}{144640757}) \ &= (1) \times {(-1)^{\frac{{144640757}^{2}}{8}}}^{2} \times (\frac{2086448}{144640757}) \ &= (1) \times (\frac{2086448}{144640757}) \ &= (1) \times {(-1)^{\frac{{144640757}^{2}}{8}}}^{2} \times (\frac{521612}{144640757}) \ &= (1) \times (\frac{521612}{144640757}) \ &= (1) \times {(-1)^{\frac{{144640757}^{2}}{8}}}^{2} \times (\frac{130403}{144640757}) \ &= (1) \times (\frac{130403}{144640757}) \ &= (1) \times (-1)^{{\frac{144640757-1}{2}}\cdot{\frac{130403-1}{2}}} \times (\frac{144640757}{130403}) \ &= (1) \times (\frac{23830}{130403}) \ &= (1) \times (-1)^{\frac{{130403}^{2}}{8}} \times (\frac{11915}{130403}) \ &= (-1) \times (\frac{11915}{130403}) \ &= (1) \times (-1)^{{\frac{130403-1}{2}}\cdot{\frac{11915-1}{2}}} \times (\frac{130403}{11915}) \ &= (1) \times (\frac{11253}{11915}) \&= (1) \times (-1)^{\frac{11915}{2}} \times (\frac{662}{11915}) \ &= (-1) \times (\frac{662}{11915}) \ &= (-1) \times (-1)^{\frac{{11915}^{2}}{8}} \times (\frac{331}{11915}) \ &= (1) \times (\frac{331}{11915}) \ &= (-1) \times (-1)^{{\frac{11915-1}{2}}\cdot{\frac{331-1}{2}}} \times (\frac{11915}{331}) \ &= (-1) \times (\frac{330}{331}) \&= (-1) \times (-1)^{\frac{331}{2}} \times (\frac{1}{331}) \ &= (1) \times (\frac{1}{331}) \ &= (1) \times (-1)^{{\frac{331-1}{2}}\cdot{\frac{1-1}{2}}} \times (\frac{331}{1}) \ &= (1) \end{aligned} $$

  4. 孙子定理

$$ \begin{aligned} {m} &= {3} \times {5} \times {7} \times {13} = 1365\{M_{1}} &= {5} \times {7} \times {13} = {455} \{M_{2}} &= {3} \times {7} \times {13} = {273} \{M_{3}} &= {3} \times {5} \times {13} = {195} \{M_{4}} &= {3} \times {5} \times {7} = {105} \\end{aligned} $$$$ \begin{aligned} {455} &= {151} \times {3} + {2} \{3} &= {1} \times {2} + {1} \{2} &= {2} \times {1} + {0} \ \end{aligned} $$ $$ \begin{aligned} {1} &= ({1}) \times {3} + ({-1}) \times {2} \ &= ({1}) \times {3} + ({-1}) \times ({455} - ({151}) \times {3}) \ &= ({-1}) \times {455} + ({152}) \times {3} \ \end{aligned} $$$$ \therefore M_{1}^{'} = {2} $$$$ \begin{aligned} {273} &= {54} \times {5} + {3} \{5} &= {1} \times {3} + {2} \{3} &= {1} \times {2} + {1} \{2} &= {2} \times {1} + {0} \ \end{aligned} $$ $$ \begin{aligned} {1} &= ({1}) \times {3} + ({-1}) \times {2} \ &= ({1}) \times {3} + ({-1}) \times ({5} - ({1}) \times {3}) \ &= ({-1}) \times {5} + ({2}) \times {3} \ &= ({-1}) \times {5} + ({2}) \times ({273} - ({54}) \times {5}) \ &= ({2}) \times {273} + ({-109}) \times {5} \ \end{aligned} $$$$ \therefore M_{2}^{'} = {2} $$$$ \begin{aligned} {195} &= {27} \times {7} + {6} \{7} &= {1} \times {6} + {1} \{6} &= {6} \times {1} + {0} \ \end{aligned} $$ $$ \begin{aligned} {1} &= ({1}) \times {7} + ({-1}) \times {6} \ &= ({1}) \times {7} + ({-1}) \times ({195} - ({27}) \times {7}) \ &= ({-1}) \times {195} + ({28}) \times {7} \ \end{aligned} $$$$ \therefore M_{3}^{'} = {6} $$$$ \begin{aligned} {105} &= {8} \times {13} + {1} \{13} &= {13} \times {1} + {0} \ \end{aligned} $$ $$ \begin{aligned} {1} &= ({1}) \times {105} + ({-8}) \times {13} \ \end{aligned} $$$$ \therefore M_{4}^{'} = {1} $$$$ \begin{aligned} {x} &\equiv \sum_{i=1}^{4} {{M}{i}\cdot{M}{i}^{'}\cdot{b}_{i}}; mod ; {m} \ &\equiv ({2} \times {455} \times {1} + {2} \times {273} \times {2} + {6} \times {195} \times {4} + {1} \times {105} \times {6} ); mod ; {1365} \ &\equiv {487} ; mod ;{1365} \ \end{aligned} $$

  1. 线性同余方程

    $$ \begin{aligned} &\because (28, 21, 35) = 7\ &\therefore{28} {x} ;\equiv; {21};mod;{35} \&\therefore{4} {x} ;\equiv; {3};mod;{5} \ \end{aligned} $$$$ \begin{aligned} {5} &= {1} \times {4} + {1} \{4} &= {4} \times {1} + {0} \ \end{aligned} $$ $$ \begin{aligned} {1} &= ({1}) \times {5} + ({-1}) \times {4} \ \end{aligned} $$$$ \begin{aligned} \therefore {x} ;&\equiv; {2};mod;{5} \ \therefore {x} ;&\equiv; {2};mod;{35} \{x} ;&\equiv; {7};mod;{35} \{x} ;&\equiv; {12};mod;{35} \{x} ;&\equiv; {17};mod;{35} \{x} ;&\equiv; {22};mod;{35} \{x} ;&\equiv; {27};mod;{35} \{x} ;&\equiv; {32};mod;{35} \\end{aligned} $$

  2. 欧拉/费马定理

    $$ \begin{aligned} &\because \varphi({5}) = 4\&\therefore {a}^{\varphi({p})} \equiv {7}^{4};mod;{5} \ \end{aligned} $$ $$ \begin{aligned} {7}^{1005} &\equiv {({7} ^ {4})}^{251} \times {7}^{1};mod;{5} \ &\equiv {7}^{1};mod;{5} \ &\equiv {2};mod;{5} \ \end{aligned} $$

  3. RSA计算和生成

$$ \begin{aligned} & guess;p \&p = {851181} \&p = {1034041} \&p = {538487} \& guess;q \&q = {800121} \&q = {757479} \&q = {859255} \&q = {728437} \\end{aligned} $$$$ \begin{aligned} & random;prime;{p} = {538487} \& random;prime;{q} = {728437} \& {n} = {p} \times {q} = {538487} \times {728437} = {392253854819} \& \varphi({n}) = (p - 1)(q - 1) = ({538487} - 1)({728437} - 1) = {392252587896} \& random;select;e;from;{3};to; 392252587896; which; makes; (e, \varphi(n)) = 1 \& e = {147067583149} \& calculate; d; which; makes; ed \equiv {1} ;mod;\varphi(n) \ \end{aligned} $$$$ \begin{aligned} {392252587896} &= {2} \times {147067583149} + {98117421598} \{147067583149} &= {1} \times {98117421598} + {48950161551} \{98117421598} &= {2} \times {48950161551} + {217098496} \{48950161551} &= {225} \times {217098496} + {102999951} \{217098496} &= {2} \times {102999951} + {11098594} \{102999951} &= {9} \times {11098594} + {3112605} \{11098594} &= {3} \times {3112605} + {1760779} \{3112605} &= {1} \times {1760779} + {1351826} \{1760779} &= {1} \times {1351826} + {408953} \{1351826} &= {3} \times {408953} + {124967} \{408953} &= {3} \times {124967} + {34052} \{124967} &= {3} \times {34052} + {22811} \{34052} &= {1} \times {22811} + {11241} \{22811} &= {2} \times {11241} + {329} \{11241} &= {34} \times {329} + {55} \{329} &= {5} \times {55} + {54} \{55} &= {1} \times {54} + {1} \{54} &= {54} \times {1} + {0} \ \end{aligned} $$ $$ \begin{aligned} {1} &= ({1}) \times {55} + ({-1}) \times {54} \ &= ({1}) \times {55} + ({-1}) \times ({329} - ({5}) \times {55}) \ &= ({-1}) \times {329} + ({6}) \times {55} \ &= ({-1}) \times {329} + ({6}) \times ({11241} - ({34}) \times {329}) \ &= ({6}) \times {11241} + ({-205}) \times {329} \ &= ({6}) \times {11241} + ({-205}) \times ({22811} - ({2}) \times {11241}) \ &= ({-205}) \times {22811} + ({416}) \times {11241} \ &= ({-205}) \times {22811} + ({416}) \times ({34052} - ({1}) \times {22811}) \ &= ({416}) \times {34052} + ({-621}) \times {22811} \ &= ({416}) \times {34052} + ({-621}) \times ({124967} - ({3}) \times {34052}) \ &= ({-621}) \times {124967} + ({2279}) \times {34052} \ &= ({-621}) \times {124967} + ({2279}) \times ({408953} - ({3}) \times {124967}) \ &= ({2279}) \times {408953} + ({-7458}) \times {124967} \ &= ({2279}) \times {408953} + ({-7458}) \times ({1351826} - ({3}) \times {408953}) \ &= ({-7458}) \times {1351826} + ({24653}) \times {408953} \ &= ({-7458}) \times {1351826} + ({24653}) \times ({1760779} - ({1}) \times {1351826}) \ &= ({24653}) \times {1760779} + ({-32111}) \times {1351826} \ &= ({24653}) \times {1760779} + ({-32111}) \times ({3112605} - ({1}) \times {1760779}) \ &= ({-32111}) \times {3112605} + ({56764}) \times {1760779} \ &= ({-32111}) \times {3112605} + ({56764}) \times ({11098594} - ({3}) \times {3112605}) \ &= ({56764}) \times {11098594} + ({-202403}) \times {3112605} \ &= ({56764}) \times {11098594} + ({-202403}) \times ({102999951} - ({9}) \times {11098594}) \ &= ({-202403}) \times {102999951} + ({1878391}) \times {11098594} \ &= ({-202403}) \times {102999951} + ({1878391}) \times ({217098496} - ({2}) \times {102999951}) \ &= ({1878391}) \times {217098496} + ({-3959185}) \times {102999951} \ &= ({1878391}) \times {217098496} + ({-3959185}) \times ({48950161551} - ({225}) \times {217098496}) \ &= ({-3959185}) \times {48950161551} + ({892695016}) \times {217098496} \ &= ({-3959185}) \times {48950161551} + ({892695016}) \times ({98117421598} - ({2}) \times {48950161551}) \ &= ({892695016}) \times {98117421598} + ({-1789349217}) \times {48950161551} \ &= ({892695016}) \times {98117421598} + ({-1789349217}) \times ({147067583149} - ({1}) \times {98117421598}) \ &= ({-1789349217}) \times {147067583149} + ({2682044233}) \times {98117421598} \ &= ({-1789349217}) \times {147067583149} + ({2682044233}) \times ({392252587896} - ({2}) \times {147067583149}) \ &= ({2682044233}) \times {392252587896} + ({-7153437683}) \times {147067583149} \ \end{aligned} $$$$ \begin{aligned} & \therefore d = 385099150213\& \therefore PublicKey:(n, e) = (392253854819, 147067583149) \& \therefore PrivateKey:(PublicKey(n, e), p, q, d) = ((392253854819, 147067583149), 538487, 728437, 385099150213) \ \end{aligned} $$

$$ \begin{aligned} & PublicKey:(n, e) = (745840172411, 283800806167) \& PrivateKey:(PublicKey(n, e), p, q, d) = ((745840172411, 283800806167), 846673, 880907, 19922900743) \ \end{aligned} $$$$ \begin{aligned} &plain ;text:;qwe \ & \xrightarrow{base16encode};717765\& \xrightarrow{int;by;hex} {7436133} \& \xrightarrow{encrypto}; {7436133}^{283800806167};mod;{745840172411} \& \rightarrow crypto number:627561158974\& \xrightarrow{encode} crypto text:921d8f593e\ \end{aligned} $$ $$ \begin{aligned} & PublicKey:(n, e) = (745840172411, 283800806167) \& PrivateKey:(PublicKey(n, e), p, q, d) = ((745840172411, 283800806167), 846673, 880907, 19922900743) \ \end{aligned} $$$$ \begin{aligned} & crypto ;text: ;921d8f593e\ & \xrightarrow{decode};{627561158974} \ & \xrightarrow{decrypto};{627561158974}^{19922900743};mod;{745840172411} \& \rightarrow {7436133} \& \xrightarrow{hex;by;int} {717765} \& \xrightarrow{base16decode} {qwe} \ \end{aligned} $$

  1. 椭圆曲线
  2. E-Gimo
  3. 希尔密码(矩阵)

需要用到的内容

  1. python语言
  2. Latex语言
  3. 自定义每个模块的基类,设置适当的抽象方法,子类继承后分为求结果和求过程的类,在演示的时候调用求过程的类,在其他模块中调用求结果的类
  4. 每个需求自定义一个模块文件
  5. 一个gui库对所有模块进行整合,暂定为pyqt(pyside2)
  6. 部分使用多线程对运行速度进行优化

$$ \begin{aligned} &plain ;text:;qwe \ & \xrightarrow{base16encode};b'717765'\& \xrightarrow{encrypto}; {7436133}^{347698531631};mod;{519925937617} \& \rightarrow crypto number:157917227726\& \xrightarrow{encode} crypto text:24c499aace\ \end{aligned} $$

$$ \begin{aligned} & crypto ;text: ;24c499aace\ & \xrightarrow{decode};{157917227726} \ & \xrightarrow{decrypto};{157917227726}^{292581295151};mod;{519925937617} \& \rightarrow {717765} \& \xrightarrow{base16decode} {qwe} \ \end{aligned} $$

$$ \begin{aligned} &plain ;text:;qwe \ & \xrightarrow{base16encode};717765\& \xrightarrow{int;by;hex} {7436133} \& \xrightarrow{encrypto}; {7436133}^{342541082263};mod;{423741227251} \& \rightarrow crypto number:234427889489\& \xrightarrow{encode} crypto text:3694fdb751\ \end{aligned} $$

$$ \begin{aligned} & crypto ;text: ;3694fdb751\ & \xrightarrow{decode};{234427889489} \ & \xrightarrow{decrypto};{234427889489}^{302803764391};mod;{423741227251} \& \rightarrow {7436133} \& \xrightarrow{hex;by;int} {717765} \& \xrightarrow{base16decode} {qwe} \ \end{aligned} $$

number-theory-calculator's People

Contributors

alwaysstudent avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.