Working on a project, I have this issue where my array “slicetable” returns undefined every time, and I do not know how to solve this problem. I have a function that generates an array of likelihoods for cryptographic key lengths – I then need to split the text into individual strings of n-th keys, up to the length of the “key”. I’ve worked for the last 4 hours on this problem, and don’t know where to begin. If anyone could recommend a good strategy for tackling problems like this, as well as helping me out on this one, that would be great – I’m still quite new to all of this.
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;
}
}
Don’t you mean this: (break instead of return)