Function That Gives Back Nothing

I've been facing a challenge with my project where the array "slicetable" keeps returning undefined, and I'm stuck on how to resolve this issue. My task involves creating an array of likelihoods for cryptographic key lengths and then splitting the text into individual strings of nth keys based on the length of the specified key. I've spent the past 4 hours trying to troubleshoot this, but I'm at a loss on where to start. If anyone has any advice on effective strategies for tackling problems like this or can offer assistance with this particular issue, I would greatly appreciate it - as I am still relatively inexperienced in this field.

function vigenerekey(text, max) {
    // Standardize the text
    text = text.split(" ").join("").toUpperCase();
    // Obtain our list of key length probabilities
    var probabilities = vigenerekeylength(text, max);
    // Extend the Math.max to arrays
    Array.max = function(array){
        return Math.max.apply(Math, array);
    };

    // Find the position of the most probable key length
    for (var d = 0; d <= 12; d++) {
        if (probabilities[d] === probabilities.max) {
            return;
        }
    }
    // Slice the text into [d] parts (the length of the key)
    var slicetable = ['','','','','','','','','','','','','','','','','','','','',''];
    var chiresults = [];
    for (var e = 0; e <= d; e++){
        for (f = 0; f <= text.length; f++) {
            if (f % e === 0) {
                slicetable[e] += text.charAt(f);        
            }
        }
    return slicetable;
    }

}

Answer №1

Perhaps you intended to use "break" instead of "return" in this context:

// Locate the position with the highest likelihood for the key length 
for (var index = 0; index <= 12; index++) { 
    if (probabilities[index] === probabilities.max) { 
        break;
    } 
} 

Answer №2

The issue lies in the return statement located within your for-loop. It is recommended to use

break;  

instead of

return; 

Upon realizing a typo in my initial response (being the first one to provide an answer), a moderator removed it. I have rectified the error, but unfortunately, I am unable to restore the deleted content... Therefore, here is my revised explanation.

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

The window fails to load properly after building, but functions perfectly while in development server mode

My application is not displaying a window after it's built, but it works perfectly fine when I execute npm run serve Even though there is a process running in the task manager, the same issue persists if I try using the installer. I'm not receiv ...

Understanding the behavior of Bootstrap input-groups when containing hidden sub elements

In a scenario where a button and an input field are enclosed within a div with a bootstrap class named input-group, they expand to occupy the entire width of the enclosing element. However, if the button is hidden, the input field unexpectedly contracts to ...

Bootstrap: nav-link remains visible even after a dropdown-item is chosen

I am aiming to accomplish the following - when a dropdown-item from the navbar is selected, I want to execute BOTH of the following actions: Scroll to the div with the specified target id Collapse the navbar back to its initial state (fully rolled up, hi ...

Challenges with loading content and async JavaScript within websites

I decided to replace the content on index.htm with the content from project.htm. By clicking on a#front, it redirects to project.htm and dynamically updates the content. However, I am facing an issue regarding how to run the javascript that accompanies thi ...

Parameters for an Ajax Jquery function

I have a working code that I would like to make more generic. This code submits a form using Ajax and receives the following json: {"message": "Verifique todos los campos","success": "false"} Depending on success or failure, it adds a class to my #MESSA ...

What is the process for reversing the texture application direction on a CylinderGeometry object?

Is it possible to reverse the orientation of texture mapping on a CylinderGeometry object? var obj = new THREE.Mesh( new THREE.CylinderGeometry(20, 15, 1, 20), new THREE.MeshLambertMaterial({color: 0x000000}) //the material is later changed to the ...

transferring scoped model information to the controller

When using AngularJS, my view is structured like this: <div class="sli1" ng-init="values=[10,20,30,40,50]" <div class="sli2" ng-init="values2=[10,20,30,40,50]" I am attempting to send the initial data models back to the controller for retrieva ...

Ways to implement the don't repeat yourself (DRY) principle in React JS with condition-based logic

https://i.stack.imgur.com/xkrEV.gif Here is a sample way to use the component: import React from "react"; import MyAvatars from "../../components/MyAvatar/MyAvatars"; const About = () => { return ( <MyAvatars ...

Retrieve characters preceding and following a space (JavaScript)

In my Angular component, I have a phone number field. For example, +36 42534534534 I am trying to extract the code before the space and the phone number after the space. This is how I am currently handling it: set phoneNumberResult(value: string) { ...

What technique can be used to shift focus to the following text field after clicking a button

HTML : <input type="text" class="mytextbox"> <input type="text" class="mytextbox"> <input type="text" class="mytextbox"> <input type="text" class="mytextbox"> <input type="button" class="mybutton" value="focus next" onclick="f ...

Can JSON data be retrieved from an API using WebAssembly and then manipulated in JavaScript?

I'm just starting to explore webassembly and I am attempting to manipulate JSON data that I fetch from either a file or URL within a Webassembly compiled module. My goal is to access this JSON in JavaScript so that I can effectively read and manipulat ...

Displaying JSON data in VUE.js

I have created an API using Node.js where sending certain parameters results in a response with information about the same person but in different languages. I am struggling to present it as shown in the second example. This is how I currently receive the ...

How can I simulate keyboard events in Angular using a button click?

I've included separate buttons for Ctrl+z and Ctrl+y functionalities. When these buttons are clicked, I want them to perform the respective undo and redo actions programmatically. Below is the code snippet for this functionality. undoText(event:MouseE ...

I'm puzzled about what could be behind this error message Error [ERR_HTTP_HEADERS_SENT], especially since I've only sent the response header once. How can I figure out the cause

Here is a snippet of code from my routes file: router.get('/api/', async function(request, response){ let entries = await Entries.find({}, function(error){ if(error) console.log(error); }); let catArray = []; entrie ...

Removing a user using Vue.js in combination with Firebase

Having trouble removing an account from Firebase in vue.js. Followed the firebase docs but it's not working as expected. Here is the button to delete: <template> [...] <div class="text-center"> <button type="button" class ...

Displaying today's date in a date picker on an HTML 5 form

Is there a way to set the current date as a placeholder in an HTML 5 form using the code below? Date: <input type="date" placeholder="mm/dd/yyyy" name="date" /> ...

Guide to building a personalized dropdown menu with user input using Ant Design Vue and Vue 3

I'm trying to implement a customized dropdown using antdv, but the example provided in the documentation () doesn't cover how to do it based on user input. Here's my attempt: https://codesandbox.io/s/custom-dropdown-ant-design-vue-3-2-14-fo ...

What is the best way to split JSON parsed information when multiple encodings are applied?

I currently have a single query that I send the outcome through json. Now, I am looking to create multiple other queries within the same file and also transmit them as json data. My concern is: How can I differentiate the parsed json data when using multi ...

Issue with DWR and Android web browser

I recently encountered an issue while trying to access an application through the Android browser. The application uses DWR to maintain connections with connected clients. Everything seems to be working fine, except for the fact that if there is a 2-minut ...

Tsyringe - Utilizing Dependency Injection with Multiple Constructors

Hey there, how's everyone doing today? I'm venturing into something new and different, stepping slightly away from the usual concept but aiming to accomplish my goal in a more refined manner. Currently, I am utilizing a repository pattern and l ...