Currently working on a script using google-apps-script, open to any suggestions or ideas

Challenge: I am working on creating arrays to store values and iterate until a specific value is reached. Ultimately, this code will be used to match one letter to another, similar to how the WWII Bombe machine functioned, but in a purely digital format. The Bombe machine was used to decode messages by mapping one letter to another. I am attempting to decrypt messages using this method.

Knowledge: My coding experience is limited, especially with google-apps-script. While I have a basic understanding, I struggle with syntax differences, like using Logger.log(data); instead of System.out.print();. I have made some progress, which you can find here.

Context: I realize this is a lot to take in, but please hear me out before dismissing my query. The link under "Enigma example" in the comment above showcases the reverse mapping I aim to achieve. However, I am stuck on creating loops and variables. I have gathered information on the Enigma and Bombe machines, which you can access here. My searches online have been futile, only leading me to basic loop examples.

Assistance Needed: I require help with creating loops, variables, and arrays. Suggestions and guidance are invaluable to me as my goal is to learn rather than have my work completed by others.

Concepts: Some concepts I am considering are garbage collectors, multi-dimensional arrays, and exploring different sequences of possibilities. For more details, refer to the "Enigma & Bombe info" link mentioned earlier.

For easier copying and 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);

    var fastRotorValue = fastRotor[i];

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

      for (var k=0; k < 26 ; k++) {
        var slowRotorValue = slowRotor[k];
        Logger.log("---- XXXX " + fastRotorValue + " " + medRotorValue + " " + slowRotorValue);
      };
    }
  }
}

Answer №1

Check out the code below that I tweaked a bit to display the Loop values in the Logger print out.

function customCode() {
  var letters = ["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 firstLoop = letters;                 
  var secondLoop = letters;

  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 firstLoopValue = letters[i];
      var secondLoopValue = secondLoop[j];

      Logger.log("---- " + firstLoopValue + " " + secondLoopValue);

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

        Logger.log('---- XXXX Third Loop value of k : ' + k);
        var firstLoopValue = letters[i];
        var secondLoopValue = secondLoop[j];
        var thirdLoopValue = letters[k];

        Logger.log("---- XXXX " + firstLoopValue + " " + secondLoopValue + " " + thirdLoopValue);
      };
    }

  }
}

Give it a test run and share your thoughts. It might not be perfect, but it's a good starting point.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is anyone else experiencing issues with the jQuery slide-in not working on a particular website? How can I determine which version of jQuery is compatible with this site?

Essentially, I am looking to have a div box slide in on the page as it loads. This method has worked successfully on other websites and HTML previews that I have tested it on so far. However, for some reason, it does not seem to work on this specific websi ...

Guide on How to Retrieve the Following YouTube Video using a PHP Array

I have a PHP/HTML script that currently loads a random YouTube video from an array every time the page is refreshed. However, I am looking to add functionality for next and previous buttons to allow users to cycle through the videos in the array. The goal ...

Instructions on dynamically positioning a collection of div elements at the center of a webpage container

I am looking to create a set of divs that are centered on the page and adjust in size according to the length of the username. .Container1 { display: table; width: 100%; padding:0; margin:0; -webkit-box-sizing: border-box; -moz-box-sizing: bor ...

Is it possible for me to pass a reference to a specific object's instance function?

Can JavaScript allow you to pass a function reference to a specific object's function, similar to what can be done in Java? Let's take a look at this code snippet: _.every(aS, function (value) { return exp.test(value); }); What if we want ...

What are the steps to apply an AngularJS filter for formatting values within an array?

While I have experience using angular filters for formatting primitive values like numbers into currency formats, I am now faced with the challenge of applying the same filtering to an array of values. For example: price = 1 prices = [1,2,3] If I were to ...

Tips for extracting data from a state-based object store in React?

https://i.sstatic.net/A0cc4.pngWhenever I attempt to execute a PUT call, I fetch the data by id and save it in a state named "getData". While I am able to filter and map over this data, I face issues when trying to extract individual values. For instance, ...

Using jQuery, you can easily modify the color of a TD cell by applying the css properties assigned to the div element

I am attempting to implement a jQuery script that will execute upon the loading of the document. The objective is for the script to retrieve the background color of a div located within a td cell and apply it as the background color for the respective td c ...

What is the process for uploading files using AngularFire on Firebase Storage?

Despite watching multiple videos and tutorials, I am encountering a 403 error while working with Angular 1. To solve the issue of ng-model not supporting files, I created an Angular directive named file-model: app.directive('fileModel',['$ ...

Disabling the search function when it is clicked (before any actions are taken)

I've recently implemented a search form on my website, where the search field opens up upon clicking the search icon.https://i.stack.imgur.com/UeErx.png To make the search icon clickable, I disabled the search function. var $searchBtn = $search.find ...

Creating a Javascript Regular Expression to detect both accented and non-accented variations of a given string

Is there a way to use regular expressions in JavaScript to match both accented and non-accented versions of a string? I am customizing jQuery-ui's autocomplete feature by adding bold HTML tags around words in the suggestions. Here is my code snippet: ...

Achieve the appearance of table-like alignment without the need for traditional tables

Any ideas on how to achieve the following layout: <table border="0"> <tbody> <tr> <td style="margin-right:5px;"> <h2 id="optiona" class="option optiona optiona2">a. aa </h2> </td> ...

Retaining original input value even when validation is applied with input type="number"

Encountering an unusual scenario while using angularJs and input type="number". It seems that if the initial value of an input falls outside the specified min and max range, the value gets wiped out. To better visualize the issue, I created a fiddle - htt ...

Dependency management in ReactJS components

I am grappling with the optimal structure for a React component that is composed of other components. Let's look at the first example: <ColorSelect id="color" label={this.state.selectLabel} trigger={{ color: "lime", text: "Lime"}} onPropagateCli ...

dealing with applying functions to multiple data frames

I need help applying a function to a list of data frames containing georeferenced points. My goal is to add a new column to each data frame that contains information about the cell id where each point falls. Here is the function I am using: vectorData < ...

How to create a continuous loop for a JavaScript carousel

I have a simple carousel set up with this code. I'm looking to make it loop back to the beginning after reaching the third quote-item. Can anyone provide some guidance? Thank you! This is the JavaScript used: <script> show() $(functi ...

Consolidating multiple inputs into a single saved value

How can I combine three input values into one input field using onchange event in JavaScript? <script type="text/javascript"> function updateInput($i){ $('updateval').val($i); } </script> <input type="text" onchange="updat ...

Create a dynamic slideshow using a bootstrap carousel in conjunction with the powerful php glob() function

I'm struggling to create a homepage featuring a slider that pulls images dynamically from a subfolder within the Wordpress uploads directory. Here's my code: <div id="" class="carousel slide" data-ride="carousel"> <!-- Wrapper for sl ...

Having difficulty transforming the JSON data into the necessary format for Google Charts using JavaScript

The JSON data returned by the following controller is structured as shown below: [ {"classification":"CON","count":2}, {"classification":"PUB","count":1}, {"classification":"SENS","count":1} ] However, Google Charts requires the data to be in the followi ...

Grab the code snippet from JSFiddle

I apologize for the seemingly simple question, but I have been struggling with it. I tried looking at similar questions, but I couldn't find a solution. Despite copying the code from http://jsfiddle.net/sB49B/21/, I can't seem to get it to work ...

When I populate an array with duplicate records until a specific number is reached, the result is an array filled with those records. I then use

My code function involves extracting 4 rows from a table, storing them in an array, and then repeating them until there are a total of 20 entries in the array. After that, it echoes the contents using a foreach loop. However, I encounter an issue where an ...