#Please do not post homework #Lucy Martinez, 04-17-2024, Assignment 24 # Problem 1: Decide whether you would like to sign up for the annual field trip # to the Princeton cemetery followed by a free dinner. # Due to the size of the class, there are two dates, # each of them limited to eight people. # ANSWER: [6] print([6]): # Problem 2: Generalize # AliceToBob(M,Nbob,eBob,Nalice,dAlice,H) # and BobReadAlice(MS,Nbob,dBob,Nalice,eAlice,H) to # AliceToBobG(ListM,Nbob,eBob,Nalice,dAlice,H) # and BobReadAliceG(MS,Nbob,dBob,Nalice,eAlice,H) # where ListM is an arbitrary list of integers each between 1 and Nbob, # and the signature is the sum of the integers in List M cubed mod H. # The encrypting and descryting is done separately for each member of ListM. AliceToBobG:=proc(ListM,Nbob,eBob,Nalice,dAlice,H) local ListMsum,i,x,M1,S: ListMsum:=add(i,i in ListM): if ListMsum<=1 and ListMsum>=Nbob then print(`Sum of elements in ListM must be between 1 and Nbob`): return(FAIL): fi: M1:=[]: for i from 1 to nops(ListM) do M1:=[op(M1),ListM[i]&^eBob mod Nbob]: od: x:=ListMsum&^3 mod H: S:=x&^dAlice mod Nalice: [M1,S]: end: BobReadAliceG:=proc(MS,Nbob,dBob,Nalice,eAlice,H) local i,Mlist,S,M,Msum,X,X1: Mlist:=MS[1]: #this was M1 S:=MS[2]: M:=[]: for i from 1 to nops(Mlist) do M:=[op(M),Mlist[i]&^dBob mod Nbob]: od: Msum:=add(i,i in M): X:=Msum&^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: # Problem 3: # Look at the class mailing list and find the three students right after you # Email them your public ([N,e]) part of your public key (but keep d to yourself). # Also email them your public H (so the Hash function is M^3 mod H) # Ask them to email you THEIR [N,e] but to keep their d to themselves # Convert your birthday to an integer: mm/dd/yyyy -> mmddyyyy. # For example July 2, 1950 becomes the integer 02071950 (same as 2071950) # This is your secret message. Then for two of them sign them the right way, # but for one of them sign it the wrong way # Ask them to send you back your birthday, and wether they believe it is you # All together you should have six email exchanges # Describe in detail all these interactions (on both ends), # including the RSA keys and the Hash chosen ###################################C24.txt Help24:=proc(): print(`MakeRSAkey1(K) , MakeRSAkey(K,M) `): print(`AliceToBob(M,Nbob,eBob,Nalice,dAlice,H)`): print(`BobReadAlice(MS,Nbob,dBob,Nalice,eAlice,H)`): end: 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: