# PART 1: FIELD TRIP: # ----------------------- # can't attend either date :( PrincetonTrip:=proc(): return {}; end; # PART 2: AliceToBobG() AND BobReadAliceG() PROCEDURES: # ----------------------- AliceToBobG:=proc(ListM,Nbob,eBob,Nalice,dAlice,H) local ListEncrypted, i, MsgSum, x: ListEncrypted:=[seq(0, i=1..nops(ListM))]; MsgSum:=0; for i from 1 to nops(ListM) do: ListEncrypted[i]:=ListM[i]&^eBob mod Nbob: MsgSum:=MsgSum + ListM[i]; od; x:=M&^3 mod H: S:=x&^dAlice mod Nalice: return [ListEncrypted,S]; end; BobReadAliceG:=proc(MS,Nbob,dBob,Nalice,eAlice,H) local M, ListDecrypted, S, M, X, X1: M:=MS[1]; ListDecrypted:=[seq(0, i=1..nops(M))]; MsgSum:=0; for i from 1 to nops(M) do: ListDecrypted[i] = M[i]&^dBob mod Nbob; MsgSum:=MsgSum+ListDecrypted[i]; od; M:=M1&^dBob mod Nbob: X:=MsgSum&^3 mod H: X1:=S&^eAlice mod Nalice: if X<>X1 then print(`You are not Alice, I will call the police`): fi: return ListDecrypted; end; # PART 3: BIRTHDAY INVITATIONS: # ----------------------- # my key (N,e,H sent to Auora, Dayoon, and Joseph): # ---------------- # N: 1683754217202490906164766558327928523357546213001574736860199666524321814696638401095728964263656048837717014950752654281983486441056347749832389567540880927371903356051823175473798510569159751669859083 # e: 468668896800796200411805561247540139594347762467718928212803510121346092919653795459577619291283044182463566958891034881670416221495681360377778687409818864301641200629744957532443474679991280602813355 # d: 745126340437265011619414116522457153893167710323611184187002539003556683806739524317191142237365115489263221489383970290435594604687467930962660983289220505449152841763438258658108216576026593297115683 # H: 271828182845904 # my birthday: 10/19/2004 (10192004) # messages received: # ---------------- # from Shaurya: # N: 741722208453803540319268247178773400187219540755637048600837667643712077137100784815902032907627202684725052133657977388430721940565969634497741991891629104756024347555919826922991511673210444430067957 # e: 468739773739813145043673147966921765247165617762303145800598594443673848897972709733443148896181442846999006871294294927232006568386142154050238811213459916690546269900022300085480318862425218862758487 # H: 161803399 # MS: [877153888307098739283982846956862096286240739619932988842215018212432735000720232814576195781940686668466754049011023760317535113551614509473309523519204427262688762544541474213111362056512898943569549, 77653645406905473989067270851811706614219930884466892818217204524297738991967674899932188657153486067779892878015596544656522880385220895923016728901871919610860214690517590905140795556813779458981805] # His signature is correct, and his birthday is 4/25/2004 # from Robert: # N: 781031698217883042398890730588167007882753212312082463232625329429118308310700557226161167257864287497112646594083423739642856291713565876625980189273341617453296899265578536263772290719418809181289833873674466243735227170670747623731988888385475296513452691261296092088186595847190487484931619714612529041666895402387685839287384762848588078447029927783219111285572597724398689074360810786955072555913196849206252722952514822675486809906466904331236284216176894185287595913548875533977388179481458323646315143278086824654932577425491784595310574742954469002750038852791885437112141385501497033688351168039005975648776602234669602153777671309634931623194197525489751480366060594189076267130414967739155316040950648115500963210117071811910989047225658621754476375166781416632894855243464523714749416318518825790970384344337623363487021750848634301101882030448509042252397897612215439718705285976714636648986158554927938016438511288092137337703354586413203223814977591982788320753945520522155052965844593510495432059323088820333396387922533145400849774252574298970423764475804862809053455077077794767512417798804364205337309645960443188549312321332618576197481427323910025987316528972695113429854135692596148192594644555765051759291023 # e: 65537 # H: 65700862949 # MS: [ 199232534276118556871282428329141934208962251163601814266038403761982954725065133304040588057612581252075309222749933037671639612878621414714044186067291912711535614828394543763279971759371422212655096, 103285230894794943057212399803176399946470785340236529668721156380000196638077149216589329827310147812488861459340439137102873419302609697032340308135332079374875457809918573780636715892328745418192853764706107686498974692900398751706246633529495388721271612750905828556883930919633646433924238193273024217037988350602957759140254775468372037944372358683629196138070623938345087042684047671803946914539808841499063783184562678540924442774936354910033133633513405998888788056513763592461102206920714463905835077637610890357176871287770140231911651389622179760897762600829657301483080723116719638275640983813044441813796454266334457170309393035111846614014649714932593112263478945037035558552873642387362073366311851281588046051183769540533568096623819527833767360176257209925806346264059938289397471757119368369829926699836205902603743169844698809195551144213383350456215049801968192435754995332714445103799069001697408045970579449209439197548673516374883714107354964252440709145788990964415312211792536439736882446151937685705038256616250836957917031828341425126683992624322087790534788322804511051929385677238374410540325969341728978630485176184068868784111688457226921543425207355078587086386477073548108080776542956649006360867171] # His signature is correct, and his birthday is 10/15/1997 # from Pablo # (nothing received by Sunday 6pm) # messages sent: # ---------------- # from Aurora: # (nothing received by Sunday 6pm) # from Dayoon: # (nothing received by Sunday 6pm) # from Joseph: # N: 1566257182390879657957 # e: 962437938162041021459 # MS (correct signature): [] # He correctly decrypted my birthday ############################################################## OLD CODE ############################################################## with(numtheory): #MakeRSAkey1(K): makes a triple [N,e,d] where N,e, are public and d private #one try MakeRSAkey1:=proc(K) local P,Q,ra,N,e,d: ra:=rand(10^K..10^(K+1)): P:=nextprime(ra()): Q:=nextprime(ra()): if P=Q then RETURN(FAIL): fi: N:=P*Q: e:=rand(1..(P-1)*(Q-1))(): if gcd(e,(P-1)*(Q-1))<>1 then RETURN(FAIL): fi: d:=e&^(-1) mod (P-1)*(Q-1): [N,e,d]: end: #MakeRSkey(K,M): tries to make an RSA key by trying M times MakeRSAkey:=proc(K,M) local m,rsa: for m from 1 to M do rsa:=MakeRSAkey1(K): if rsa<>FAIL then RETURN(rsa): fi: od: FAIL: end: #Hash function: x&^3 mod H #AliceToBob(M,Nbob,eBob,Nalice,dAlice,H):| #Inputs Alice's message M, the [Nbob,eBob] public part of #Bob's RSA key, the Nalice (public) and dAlice (private) of Alice's key #and H (public Hash function x&^3 mod H #output a pair the encrypted message, followed by the much shorter #signature AliceToBob:=proc(M,Nbob,eBob,Nalice,dAlice,H) local x,M1,S: M1:=M&^eBob mod Nbob: x:=M&^3 mod H: S:=x&^dAlice mod Nalice: [M1,S]: end: #BobReadAlice(MS,Nbob,dBob,Nalice,eAlice,H) #inputs a signed message MS=[M1,S] sent from Alice, #Nbob,dBob,Nalice, eAlice, and H outputs #the deciphered message from Alice and also checks #that it came from Alice and not from a bad guy #pretending to be Alice BobReadAlice:=proc(MS,Nbob,dBob,Nalice,eAlice,H) local M1,S,M,X,X1: M1:=MS[1]: S:=MS[2]: M:=M1&^dBob mod Nbob: X:=M&^3 mod H: X1:=S&^eAlice mod Nalice: if X<>X1 then print(`You are not Alice, I will call the police`): fi: M: end: