Giter VIP home page Giter VIP logo

rsa-toy's Introduction

RSA-toy

a RSA toy

0.先修知识

  • 1.欧几里得算法,拓展欧几里得算法
  • 2.欧拉函数
  • 3.费马小定理,欧拉定理

1.生成两个大素数 P Q

  • 1.生成一个随机的大整数
  • 2.费马小定理素性测试

2.计算 N=P*Q

3.计算N的欧拉函数K=(P-1)*(Q-1)

4.找一个正整数 E 与 K 互质

5.找出D 满足 D*E%K=1

密文=(明文**E)modN

明文=(密文**D)modN

ruby rsa.rb


公钥密钥生成程序开始
P :
109135847001057879572462659898953738096385734182809138877407321609984946891933685985358594847172176807015447556491836351091815095973952693539836579978451187999740477090429313262851480616278428318920083718528142801809571485413645243683954081454461040119096896952139862148913645628323727219095929189676045463611
****************
Q :
169546874798235329109269551684417391188634186082079247627457672954914551171165393143000826259236345604713242068944902011397151157217408520365676240938319006295488905875679203964678323182555630682616261102924636016210922199667061921733260986887995731626278711555899516422109269268876120792221286751284096034197
****************
N :
18503641787487726923087825390664635545034382473862886199213070093691820914873275061691924808839171646344448985294678558409604693255381269258548753727944764966895324705575719255411215860396981662529800988463881747270329805683532936293235106392909189530688552406293809894152507784472890654345487924622075696493470253208748515209861943029649185284910974069068568550220624218529254310521164243303545564646488245678558707039863724936672891866392818390646788096837582289888855852405502878342813392858116075554715461257944285959591243622249261245277806622433338207911772977605463717768590269287128153576463229242757375105367
****************
K :
18503641787487726923087825390664635545034382473862886199213070093691820914873275061691924808839171646344448985294678558409604693255381269258548753727944764966895324705575719255411215860396981662529800988463881747270329805683532936293235106392909189530688552406293809894152507784472890654345487924622075696493191570486949222001180210818065814155625954148803680163715759223964354812458065164175186143540079723266830017414426986574183925613201457176741275275920812095593626469439394361115283589059282016553179116436491507141570749937168554079860591554090881436166397369097424339197567354389928305565146013301797233607560
****************
E :
10001
****************
D :
10938259198842859870942428128148117722452081710376700650909676071783426182254854730999166030382680009317906449461267836948063488303751031282525770626898255222906225343402025021296981118554840074880130331346712217764442536866418030133547240175470365813961676014999400469376024999680404914357616699366634488317943062165667813265771163519288580470758988193953340378750881765031223442780930032057164331627732359159433962899119322530404496372887412741615280415082875823332618706861883757915564101441703357850454448192434535568539773385515497622251356591119417163345239600650332236109990820833242290021112211842838240684721
****************
总计用时22.3857966s

ruby Encryption.rb


请输入N
18503641787487726923087825390664635545034382473862886199213070093691820914873275061691924808839171646344448985294678558409604693255381269258548753727944764966895324705575719255411215860396981662529800988463881747270329805683532936293235106392909189530688552406293809894152507784472890654345487924622075696493470253208748515209861943029649185284910974069068568550220624218529254310521164243303545564646488245678558707039863724936672891866392818390646788096837582289888855852405502878342813392858116075554715461257944285959591243622249261245277806622433338207911772977605463717768590269287128153576463229242757375105367
请输入E
10001
请输入要加密的数字
122333444455555666666777777788888888999999999
************
密文是:
337191232283221153205864434190545619876997822142762173666427441409635490166914700476247494804949543823866213134779866561840505192961734532253587118559631042085325025822654171399359280534700226422872760930399749533202471779881438331595785108110073763206891310379839683628307037176898575630395009159348804809395638238771373144489125108656921147970659126655229001998018487816115966925263293237774299792137333263148700815688240645767375318704512269719387230567121288578225878886589157075958482582101964242571704135897707532821629177337661868856645696332735761348542783640216664940611574706942159340300875573224340735389
************

ruby Decoding.rb


请输入N
18503641787487726923087825390664635545034382473862886199213070093691820914873275061691924808839171646344448985294678558409604693255381269258548753727944764966895324705575719255411215860396981662529800988463881747270329805683532936293235106392909189530688552406293809894152507784472890654345487924622075696493470253208748515209861943029649185284910974069068568550220624218529254310521164243303545564646488245678558707039863724936672891866392818390646788096837582289888855852405502878342813392858116075554715461257944285959591243622249261245277806622433338207911772977605463717768590269287128153576463229242757375105367
请输入D
10938259198842859870942428128148117722452081710376700650909676071783426182254854730999166030382680009317906449461267836948063488303751031282525770626898255222906225343402025021296981118554840074880130331346712217764442536866418030133547240175470365813961676014999400469376024999680404914357616699366634488317943062165667813265771163519288580470758988193953340378750881765031223442780930032057164331627732359159433962899119322530404496372887412741615280415082875823332618706861883757915564101441703357850454448192434535568539773385515497622251356591119417163345239600650332236109990820833242290021112211842838240684721
请输入密文
337191232283221153205864434190545619876997822142762173666427441409635490166914700476247494804949543823866213134779866561840505192961734532253587118559631042085325025822654171399359280534700226422872760930399749533202471779881438331595785108110073763206891310379839683628307037176898575630395009159348804809395638238771373144489125108656921147970659126655229001998018487816115966925263293237774299792137333263148700815688240645767375318704512269719387230567121288578225878886589157075958482582101964242571704135897707532821629177337661868856645696332735761348542783640216664940611574706942159340300875573224340735389
************
明文是:
122333444455555666666777777788888888999999999
************

rsa-toy's People

Contributors

superkunn avatar

Watchers

James Cloos 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.