restart; with(Maplets[Elements]): sfile := proc(fname, p, q, m, f, e, d) local fd; fd := fopen(convert(fname, string), WRITE); fprintf(fd, "p = %d\n\nq = %d\n\nm = %d\n\nf = %d\n\ne = %d \n \nd = %d", p, q, m, f, e, d); fclose(fd); convert(fname, symbol); end: findd := proc(e, f) local d; if igcd(e, f) <> 1 then d := cat("The decryption exponent d does not exist. The gcd(e, f) is not equal to 1. ", "Choose a new encryption exponent for e."); Maplets:-Tools:-Set('FILES' = "", 'D'('foreground') = 'red', 'BS'('enabled') = 'false'); convert(d, symbol); else Maplets:-Tools:-Set('FILES'('value') = "rsaparam.txt", 'D'('foreground') = 'black', 'BS'('enabled') = 'true'); d := e^(-1) mod f; fi: end: gene := proc(ne, f) local e; if ne mod 2 = 0 then e := ne + 1; else e := ne + 2; fi: while igcd(e, f) <> 1 do e := e + 2; od: e; end: rsaparametert := Maplet( 'onstartup' = 'A1', Window['W1']( 'title'="RSA Parameter Creator", BoxColumn('halign' = 'none', 'background' = 'navy', BoxColumn( BoxRow('halign' = 'none', Label("Enter prime p: p = ", 'font' = Font("arial", 17)), TextBox['P']('font' = Font("arial", bold, 16), 2..50) ), BoxRow('halign' = 'none', Label("Enter prime q: q = ", 'font' = Font("arial", 17)), TextBox['Q']('font' = Font("arial", bold, 16), 2..50)), BoxRow('halign' = 'none', "Check: ", Button("Is p prime?", 'font' = Font("arial", bold, 15), Evaluate('PP' = 'isprime(P)')), TextField['PP']('editable' = 'false', 'font' = Font("arial", bold, 16), 'background' = 'white', 4), " Check: ", Button("Is q prime?", 'font' = Font("arial", bold, 15), Evaluate('QP' = 'isprime(Q)')), TextField['QP']('editable' = 'false', 'font' = Font("arial", bold, 16), 'background' = 'white', 4), " ", BoxRow( 'background' = 'yellow', BoxColumn(Label("Need help finding primes p and q? Click the following button for assistance.", 'font' = Font("arial", 17)), Button('foreground' = 'red', "Go find primes p and q", 'font' = Font("arial", bold, 15), RunWindow('W2')) ) ), HorizontalGlue())), BoxColumn( BoxRow('halign' = 'none', Button( "Compute m", 'font' = Font("arial", bold, 15), Evaluate('M' = 'P*Q' )), Label("m = ", 'font' = Font("arial", 17)), TextBox['M']( 'editable' = 'false', 'font' = Font("arial", bold, 16), 2..50 ), Button("What is m?", RunDialog('MDM'))), BoxRow(Button( "Compute f", 'font' = Font("arial", bold, 15), Evaluate('F' = '(P-1)*(Q-1)' )), Label("f = ", 'font' = Font("arial", 17)), TextBox['F']( 'editable' = 'false', 'font' = Font("arial", bold, 16), 2..50 ), Button("What is f?", RunDialog('MDF')))), BoxColumn(BoxRow('halign' = 'none', Label("Enter the encryption exponent: e = ", 'font' = Font("arial", 17)), TextBox['E']('font' = Font("arial", bold, 16), 2..40 ), Button("What is e?", RunDialog('MDWE'))), BoxRow('halign' = 'none', "Check: ", Button( "gcd(e,f)", 'font' = Font("arial", bold, 15), Evaluate('G' = "gcd", 'E', 'F' ) ), BoxRow(TextField['G']( 'editable' = 'false', 'font' = Font("arial", bold, 16), 'background' = 'white', 5 )), Button("Why check this?", RunDialog('MDG')), " ", BoxRow( 'background' = 'yellow', BoxColumn(Label("Need help finding e where gcd(e,f) = 1? Click the following button for assistance", 'font' = Font("arial", 17)), Button('foreground' = 'red', "Go find e", 'font' = Font("arial", bold, 15), RunWindow('W3') )) )), BoxRow('halign' = 'none', Button("Compute the decryption exponent d", 'font' = Font("arial", bold, 15), Action(Evaluate('D' = 'findd(E, F)' ) )), Label("d = ", 'font' = Font("arial", 17)), BoxRow(TextBox['D']( 'editable' = 'false', 'font' = Font("arial", bold, 16), 2..40 )), Button("What is d?", RunDialog('MDD')))), BoxRow('halign' = 'none', BoxColumn(Label("Click button to right to save parameters p, q, m, f, e, and d. Note that you", 'font' = Font("arial", 17)), Label("can change the default name rsaparam.txt to any file name of your choice", 'font' = Font("arial", 17))), BoxColumn(seq(VerticalGlue(), i = 1..1), TextBox['FILES']('font' = Font("arial", bold, 16), 1..25), seq(VerticalGlue(), i = 1..1)), Button['BS']("Save", 'font' = Font("arial", bold, 15), 'enabled' = 'false', Action(Evaluate('FILES' = "sfile", Argument(FILES, 'quotedtext' = 'true'), 'P', 'Q', 'M', 'F', 'E', 'D'), RunDialog('MSAVE') )), seq(HorizontalGlue(), i = 1..10)), BoxRow('halign' = 'center', 'background' = 'navy', Button( "Clear All", 'font' = Font("arial", bold, 15), Action(SetOption('P' = "" ), SetOption('Q' = "" ), SetOption('PP' = "" ), SetOption('QP' = "" ), SetOption('M' = "" ), SetOption('F' = "" ), SetOption('E' = "" ), SetOption('D' = "" ), SetOption('G' = "" ), SetOption('FILES' = "" ), SetOption('BS'('enabled') = 'false')) ), Button( "Quit", 'font' = Font("arial", bold, 15), Shutdown() )) ) ), Window['W2']('title' = "Prime Finder", BoxColumn('halign' = 'none', 'background' = 'navy', BoxColumn(BoxRow(Button("How does this window generate the primes p and q?", RunDialog('MDPQ')))), BoxColumn(BoxRow('halign' = 'none', Label("Enter First Number: ", 'font' = Font("arial", 17)), TextBox['NP']('font' = Font("arial", bold, 16), 2..60)), BoxRow(Button( "Generate p", 'font' = Font("arial", bold, 15), Evaluate('PG' = 'nextprime(NP)' )), Label("p = ", 'font' = Font("arial", 17)), TextBox['PG']( 'editable' = 'false', 'font' = Font("arial", bold, 16), 2..60 ))), BoxColumn(BoxRow('halign' = 'none', Label("Enter Second Number: ", 'font' = Font("arial", 17)), TextBox['NQ']('font' = Font("arial", bold, 16), 2..60)), BoxRow(Button( "Generate q", 'font' = Font("arial", bold, 15), Evaluate('QG' = 'nextprime(NQ)' )), BoxRow(Label("q = ", 'font' = Font("arial", 17)), TextBox['QG']( 'editable' = 'false', 'font' = Font("arial", bold, 16), 2..60 )))), BoxRow('background' = 'navy', Button( "Go Back To RSA Parameter Creator with these p and q values", 'font' = Font("arial", bold, 15), Action(Evaluate( 'P' = 'PG' ), Evaluate( 'Q' = 'QG' ), SetOption('PP' = "" ), SetOption('QP' = "" ), SetOption('M' = "" ), SetOption('F' = "" ), SetOption('D' = "" ), SetOption('G' = "" ), SetOption('NP' = "" ), SetOption('NQ' = "" ), SetOption('PG' = "" ), SetOption('QG' = "" ), CloseWindow('W2')) ), " ", Button( "Clear All", 'font' = Font("arial", bold, 15), Action(SetOption('PG' = "" ), SetOption('QG' = "" ), SetOption('NP' = "" ), SetOption('NQ' = "" )) ), " ", Button( "Close this window", 'font' = Font("arial", bold, 15), CloseWindow('W2')) ) ) ), Window['W3']('title' = "Find e where gcd(e, f)=1", BoxColumn('halign' = 'none', 'background' = 'navy', BoxColumn(BoxRow(Button("How does this window generate e?", RunDialog('MDE')))), BoxColumn(BoxRow('halign' = 'none', Label("Enter Input Number: ", 'font' = Font("arial", 17)), TextBox['NE']( 'font' = Font("arial", bold, 16), 3..55), HorizontalGlue()), BoxRow(Button( "Generate e", 'font' = Font("arial", bold, 15), Action(Evaluate('EG' = 'gene(NE, F)' ))), Label("e = ", 'font' = Font("arial", 17)), TextBox['EG']( 'editable' = 'false', 'font' = Font("arial", bold, 16), 3..50 ))), BoxRow('background' = 'navy', Button( "Go Back To RSA Parameter Creator with this e value", 'font' = Font("arial", bold, 15), Action(Evaluate('E' = 'EG'), SetOption('G' = "" ), SetOption('NE' = "" ), SetOption('EG' = "" ), SetOption('D' = "" ), CloseWindow('W3'))), " ", Button( "Clear All", 'font' = Font("arial", bold, 15), Action(SetOption('NE' = "" ), SetOption('EG' = "" )) ), " ", Button( "Close this window", 'font' = Font("arial", bold, 15), CloseWindow('W3')) ) ) ), MessageDialog['MDPQ']("The prime p will be the smallest prime that is larger than the input for first number. The prime q will be the smallest prime that is larger than the input for second number.", 'type'='information' ), MessageDialog['MDE']( "The number e found here is the smallest integer greater than the input number where gcd(e,f) = 1." , 'type'='information' ), MessageDialog['MDM']( "m = p*q.", 'type'='information' ), MessageDialog['MDF']( "f = (p-1)*(q-1).", 'type'='information' ), MessageDialog['MDWE']( "The number e is the exponent used to encrypt messages in the RSA cryptosystem.", 'type'='information' ), MessageDialog['MDG']( "In order to compute the decryption exponent d, e must have a multiplicative inverse mod f, that is, e^(-1) (mod f) must exist. The inverse will exist if gcd(e, f) = 1. If the gcd(e, f) is not equal to 1, the inverse and hence d will not exist.", 'type'='information' ), MessageDialog['MSAVE']("The parameters were successfully saved in the specified file. By default, the file will be contained in the folder (or directory) where the RSA parameter Maplet is located."), MessageDialog['MDD']( "The number d is the exponent used to decrypt messages in the RSA process. Note that d = e^(-1) (mod f) or (e*d) mod f = 1, that is, d is the multiplicative inverse of e (mod f).", 'type'='information' ), Action['A1'](RunWindow('W1')) ): Maplets[Display]( rsaparametert ): # # # # # # # # # # # # # # # # #