This time, I write to the community to ask for your help in creating the following interface. See next image


I will try to explain what that interface consists of, start with password, there the user will enter the password that will be stored in the variable password, in plaintext the sentence will be stored that the user wants to encrypt using the encryption playfair, with the encrypt button the plaintext encryption is done using the playfair encryption according to what is done in the wolfram community, finally in ciphertext the result of having encrypted the text using playfair should be shown. I would like you to please help me to do this interface, because I do not have experience in this topic.


This is what I managed to do, taking into account the suggestions I received in your comments and to show how little I understood about the creation of interfaces in MMA.

This function executes the rules of the playfair system

newpos[ubica_] := 
 Module[{pref = Flatten[ubica, 1]}, 
  Which[#[[1]] != #2[[1]] && #[[2]] != #2[[2]] & @@ 
    pref, {{First[Flatten[pref]], 
     Flatten[pref][[4]]}, {Flatten[pref][[3]], 
     Flatten[pref][[2]]}}, #[[1]] == #2[[1]] && #[[2]] != #2[[2]] & @@
     pref, {{First[Flatten[pref]], 
     Mod[Flatten[pref][[2]] + 1, 5]}, {First[Flatten[pref]], 
     Mod[Flatten[pref][[4]] + 1, 
      5]}}, #[[1]] != #2[[1]] && #[[2]] == #2[[2]] & @@ 
    pref, {{Mod[First[Flatten[pref]] + 1, 5], 
     Flatten[pref][[2]]}, {Mod[Flatten[pref][[3]] + 1, 5], 

With the final function, all the playfair encryption is performed, here the newpos function defined above is used.

final[clave_String, claro_String] := 
 Module[{txtclaro, matrix, letras, hur, pos, tomar}, txtclaro = claro;
   matrix = 
      Delete[Insert[CharacterRange["a", "z"], "ñ", 
        15], {{11}, {24}}]]], 5]; 
  If[Mod[StringLength[txtclaro], 2] != 0, 
   txtclaro = StringInsert[txtclaro, "x", -1]]; 
  letras = Partition[Characters[txtclaro], 2]; 
  txtclaro = 
   StringJoin[If[#[[1]] == #[[2]], Insert[#, "x", 2], #] & /@ letras];
   If[Mod[StringLength[txtclaro], 2] != 0, 
   txtclaro = StringInsert[txtclaro, "x", -1]]; 
  hur = Partition[Characters[txtclaro], 2]; 
  pos = Map[Position[matrix, #] &, hur, {2}]; 
  tomar = (newpos[#] & /@ pos) /. {0 -> 5}; 
  StringJoin[Extract[matrix, #] & /@ tomar]]

This is the result of my attempt to create the interface I want. Thanks to the suggestions of Kuba I was able to do it, a special mention deserves the interface created by m_goldberg because it is better made.

DynamicModule[{contra = "yeguarizo", 
  limpio = "elniñobailagustosamente"}, 
   Grid[{{Text[Style["PASSWORD", Blue, Bold, 18]], 
      Text[Style["PLAINTEXT", Blue, Bold, 18]]}, {InputField[
       Dynamic[contra], String], 
      InputField[Dynamic[limpio], String]}, {Text[
       Style["CIPHERTEXT", Red, Bold, 18]], 
      InputField[Dynamic[final[contra, limpio]]]}}, Frame -> True, 
    Background -> LightGray], 
   DefaultOptions -> {InputField -> {ContinuousAction -> False}}]]]

my attemp

  • $\begingroup$ Made those in Flash to unlock the rest of the ordeal as well a long time ago. It becomes obsolete if you are not careful. $\endgroup$ Commented May 6, 2018 at 15:24
  • 1
    $\begingroup$ Although this question doesn't show at lot of effort, it does supply enough information to answer it and it deserves an answer. It is certainly not out of scope for this site. I had an answer just about ready to post when the question was closed, so I like to see it reopened. $\endgroup$
    – m_goldberg
    Commented May 6, 2018 at 16:46
  • $\begingroup$ @DanIliescu Thanks for your advice, I have it very present. That was done in visual basic 6, that's why the image. $\endgroup$ Commented May 6, 2018 at 23:15
  • $\begingroup$ @Kuba Thank you for pointing out what commands you could use, I have been slow to understand its operation, as you will see in my publication I have only used the most basic of these commands, I will try to learn a little more so that next time I can share the code of what I've done. $\endgroup$ Commented May 6, 2018 at 23:19

1 Answer 1


Here is a start on a simple and reasonable although not optimal way of making your interface.

  {labels, fields,
   cipherKey, textIn, codeOut,
   clear, clearFields,
   encrypt, encryptText},
  clearFields[] := (cipherKey = textIn = codeOut = "");
  encryptText[] := (codeOut = textIn);  (* placeholder *)
  fields =
    {InputField[Dynamic @ cipherKey, String],
     InputField[Dynamic @ textIn, String],
     InputField[Dynamic @ codeOut, String, Enabled -> False]};
  clear = Button["Clear", clearFields[], ImageSize -> All];
  encrypt = Button["Encrypt", encryptText[], ImageSize -> All];
      Join[Transpose[{labels, fields}], {{clear, encrypt}}],
      TableAlignments -> {Right, Left}],
    Style["Playfair Encrypter", 12, Bold]]]


  • $\begingroup$ Thanks for your answer, my knowledge about the creation of interfaces are very few and mainly they are compatible with visual basic 6 because with that software I learned a little bit of interface creation. I do not know if I am allowed to publish my attempt, but it is the effort I made and I would like to share it, besides I think the approach is different. The interface that you created is phenomenal, that motivates me to learn about the creation of interfaces with mathematica, because it could serve me later. $\endgroup$ Commented May 6, 2018 at 23:39
  • $\begingroup$ @bullitohappy. GUI building in Mathematica is very different than GUI building in any of the other programming systems I am acquainted with (and they include Visual Basic), but not -- in my opinion -- especially difficult. The key concept is the wrapper Dynamic. $\endgroup$
    – m_goldberg
    Commented May 7, 2018 at 5:46
  • 1
    $\begingroup$ @bullitohappy. A good place to learn more about Mathematica GUI building is tutorial/IntroductionToDynamic (just type that into the Document Center search field). In addition to the tutorial material discussed on that documentation page, it also gives several links to other GUI-building tutorials and documentation. $\endgroup$
    – m_goldberg
    Commented May 7, 2018 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.