-
Notifications
You must be signed in to change notification settings - Fork 1
cjkjellander/cth_tda381
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
%% To compile and run. erl -sname moose -setcookie monkey Erlang R13B04 (erts-5.7.5) [source] [64-bit] [smp:8:8] [rq:8] [async-threads:0] [kernel-poll:false] Eshell V5.7.5 (abort with ^G) (moose@fugu)1> c(cth_rsa). {ok,cth_rsa} (moose@fugu)2> c(public). {ok,public} %% REMEMBER, always run the init function to start the crypto app! (moose@fugu)3> cth_rsa:init(). ok %% now you can start to generate keys. (moose@fugu)7> {E1, D1, N1, P1, Q1} = cth_rsa:gen_key(80). {65537,210046402283240746635873,1047227924417166415840843, 1025755077233,1020933698171} (moose@fugu)8> Plaintext = "poop". "poop" (moose@fugu)9> Pt = cth_rsa:int_code(Plaintext). 1886351216 %% encrypt (moose@fugu)10> Ct = cth_rsa:rsa(Pt, E1, N1). 937814851505629646636792 %% decrypt (moose@fugu)13> Pt2 = cth_rsa:rsa(Ct, D1, N1). 1886351216 (moose@fugu)14> cth_rsa:int_decode(Pt2). "poop" %% crack a code (moose@fugu)16> cth_rsa:rho(N1). 1025755077233 (moose@fugu)17> PF = cth_rsa:rho(N1). 1025755077233 (moose@fugu)18> N1 rem PF. 0 (moose@fugu)19> QF = N1 div PF. 1020933698171 %% lets distribute. %% start a node on another machine. Put the hostname of the master in %% /etc/hosts $ erl -sname sausage -setcookie monkey Erlang R13B04 (erts-5.7.5) [source] [64-bit] [smp:8:8] [rq:8] [async-threads:0] [kernel-poll:false] Eshell V5.7.5 (abort with ^G) (sausage@fugu)1> cth_rsa:init(). ok %% back to master (moose@fugu)20> cth_rsa:start_master(). <0.77.0> (moose@fugu)21> net_kernel:allow([sausage@fugu]). ok %% slave (sausage@fugu)2> net_adm:ping(moose@fugu). pong (sausage@fugu)3> nodes(). [moose@fugu] %% This machine has 8 cores, start 8 slaves. (sausage@fugu)4> cth_rsa:whos_boss(). <6490.77.0> (sausage@fugu)5> cth_rsa:slaves(8, moose@fugu). [<0.53.0>,<0.54.0>,<0.55.0>,<0.56.0>,<0.57.0>,<0.58.0>, <0.59.0>,<0.60.0>] %% back to master, do some magic. (moose@fugu)22> cth_rsa:dist_gen_key(4096). {65537, 45142638657434046444888663273933342195995797036412138047905256429319404724236080323623890740158399860558972392156555646624302142146470927525228019998865663686394112043962458313860530779931351981750584729582520938785132308393719803032744119094428197807515398199060383415645030714149353132190045782652329411700777855464907023512376836375823985516618831110684371318683083800659669334446601208606824114602106656547571254638920307643747875719258888012810450835498902611991974675147420208375801759474646948059858781414943367049966761118451510120437671530361710421882222696621883399288273136843764396182413990036703506238154773264366250026725706406184734500941185293451301289546798987870007625152537589291369464910161848056173845830322751434963616150114807742801876188530370463459100399737175714143236093005576533172862617611122259228765650170268699541648560971703420349490036060308939415087782942705214990256649651315912112848757835480132769509368694643088919619144886704587651085540829713194428828030256176637147285178637366379995264028117404619555167238565320480988838368041215870203659187467365324564539532042162566795006712850287541341332212267718754594959151315931851381349810757042154809994179788567884074636688153747763443827278593, 500086732537568475635339473459055011409563311422471651664226976100119308217082487520172232494550549638514769044077786919002178750820362606021106955149705713491414962985998585279830562157599901086542946487939431163820354309533335823420715235478624205495459204153451715333186000323395225866183068028682507210046294508722720013510926424199184675253997352011650041094072559676104251043209415721512074374353999991575080682094476031448327337899437076351514286072699726247822522698636997666721588896330280093813212467476528642047611836277883133665166274355191922907183101566684985182413042016451958626201295751358255187344526416139216837511476503851475994023647790924188102546725092010534669848439247467383344391815926708973209473499195967979244092375699449140807620467325492151540934857709523400483516556556017799428596967118633292011716355365557107559230327801655480313548977809316613890411215016898918067394403379063615835532738156053547485700405458351303447709527582619653859151605058701141403538125375097279786516278088134286891385015223965481400641178155427619961443526250376161083181696595742618859911933836439072921294132391186706235212204392505347545148342135251843780171994970374973488837919157425599742585230087555844633272089429, 18674959960069617027074913579036092793953041674071941168653210158256284415997829584123979697720511756886178672206177657305794254955324258618253812906475580027638112645299507049434992675505941152595469459321128166995008192872033694685647439649645696015427345221902239272558013937873551654504023237105577359979965684808962775155153527387766321434068794362389141715876297902853655442558163821356802682381037636749663570471336818000445417431889954824901770075963614311213946004729955822493929933974233860613743482003382619367600596654051430680665491347568879939618434722385644159273703126897116999183237979403528343238481, 26778463440181011162981888855554112702644411094501766302117423088264522505018402270403538923940302007150655512949533257501091962854646342634505300849900773048275971302343437415612357101189807135045214633598928030722967319929874090876367244607751547126435304448504341029118342367455128239891208718509558414637456112237286391190781358040339082498780904642232485702340463816088404890575715022202257755214013410495065154906390233415916633973130572072731728061301578966489020190620290490726436720719041216807004854197759571407620126229250832209749025204859082192730223233436427743459382058435789976744697418365915931495109} %% Lets try some of the challenges. %% They exist from 80 to 256 bits. Have fun! (moose@fugu)23> {C2, E2, N2} = public:chal(80). {577083856964599403382997,65537,782656130558653165730327} (moose@fugu)25> {P2, Q2} = cth_rsa:factor(N2). {1083545630759,722310263953} (moose@fugu)28> {_, D2, _, _, _} = cth_rsa:key_from_pq(P2, Q2). {65537,291927142094727138699233,782656130558653165730327, 1083545630759,722310263953} (moose@fugu)29> cth_rsa:int_decode(cth_rsa:rsa(C2, D2, N2)). "format c:\n" %% Send your decrypted results to "my-firstname"@klarna.com %% A Quadratic Sieve or a MPQS would probably be a lot nicer. %% Feel free to improve it.
About
Course material for lecture in TDA381 at Chalmers
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published