简体   繁体   中英

Working on script in google-apps-script, any suggestions?

Problem: I am creating an array, or multiple arrays, to write values, and continue doing so until a certain value is drawn. The long view for this code is to, using these values to match one letter to another. (ie The Bombe used in WWII.) Except this will be completely digital. The Bombe was a decrypter that find that one letter is able to get mapped to another. (Enigma example will be posted in comments.) I am trying to decrpyt any message using this.

Understanding: I don't remember a lot of code especially since I have never used google-apps-script before. I no basic ideas, but some of the syntax's are different I am getting lost. (ie: instead of System.out.print(); it would be Logger.log(data); . That's really all I have gotten from it so far. I have some code worked out which can be found here .

Background: This is quite a lot of text to read I understand, but hear me out before you just flag me and move on. The hyperlink posted in the above comment under the words "Enigma example" shows the mapping that I am trying to do in reverse. I however need to create loops and variables that I do not remember how to create. I have information on the Enigma and Bombe: Enigma & Bombe info . I have done some searches on Google and the like, however nothing that I understand or benefit my end goal. All I have gotten is another link, which I will post in the comments, that shows me a basic loop as they put it.

What I need help with: I am asking for help in the following: Looping, variables and arrays. Suggestions will be the most valuable to me, because I am here to learn, not get my stuff done done by asking.

Ideas: Some ideas I have are, Garbage collectors, multi-dimensional array and/or just a sequence of possibilities. (See the "Enigma & Bombe info" link above.

For easy Copy/Pasting:

  function bombeCode1() {
   var fastRotor = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N",
              "O","P","Q","R","S","T","U","V","W","X","Y","Z"];

  var mediumRotor = fastRotor;                 
  var slowRotor = fastRotor;

  var rows = 26;
  var columns = 26;

   for (var i=0; i < rows ; i++) {
    Logger.log('Outer Loop: value of i : ' + i);
   // Logger.log("Partition for Outer Loop");
   // Logger.log(" ");
    var fastRotorValue = fastRotor[i];

   for (var j=0; j < columns ; j++) {
     Logger.log('-Inner Loop value of j : ' +j);
     //var fastRotorValue = fastRotor[i];
     var medRotorValue = mediumRotor[j];

     // Logger.log("---- " + fastRotorValue + " " + medRotorValue);

      for (var k=0; k < 26 ; k++) {

     // Logger.log('---- XXXX Third Loop value of k : ' + k);
      //var fastRotorValue = fastRotor[i];
      //var medRotorValue = mediumRotor[j];
      var slowRotorValue = slowRotor[k];

       Logger.log("---- XXXX " + fastRotorValue + " " + medRotorValue + " " + slowRotorValue);
      };  //var objectNumberValuePair = {"0":"A", "1":"B",     "2":"C","3":"D","4":"E","5":"F","6":"G","7":"H","8":"I",
                          //       "9":"J","10":"K","11":"L","12":"M","13":"N","14":"O","15":"P","16":"Q","17":"R",
                          //        "18":"S","19":"T","20":"U","21":"V","22":"W","23":"X","24":"Y","25":"Z"}
                         //  Logger.log(slowRotorValue = objectNumberValuePair); 
                          //  Logger.log(medRoterValue = objectNumberValuePair);
                             //  Logger.log(fastRoterValue = objectNumberValuePair);
     }

   }
 }

Here is the code I modified a little bit, just to show the Loop values in the Logger print out.

function bombeCode1() {
  var fastRotor = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N",
                  "O","P","Q","R","S","T","U","V","W","X","Y","Z"];

  var mediumRotor = fastRotor;                 
  var slowRotor = fastRotor;

  var rows = 3;
  var columns = 6;                    

  for (var i=0; i < rows ; i++) {
    Logger.log('Outer Loop: value of i : ' + i);
    Logger.log("Partition for Outer Loop");
    Logger.log(" ");

    for (var j=0; j < columns ; j++) {

      Logger.log('----Inner Loop value of j : ' + j);

      var fastRoterValue = fastRotor[i];
      var medRoterValue = mediumRotor[j];

      Logger.log("---- " + fastRoterValue + " " + medRoterValue);

      for (var k=0; k < 6 ; k++) {

        Logger.log('---- XXXX Third Loop value of k : ' + k);
        var fastRoterValue = fastRotor[i];
        var medRoterValue = mediumRotor[j];
        var slowRotorValue = slowRotor[k];

        Logger.log("---- XXXX " + fastRoterValue + " " + medRoterValue + " " + slowRotorValue);
      };
    }

  }
}

Run it and see what you think. I'm sure it's not what you need, but got to start somewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM