Insert words for phonetic Base64

Test script for phonetic Base64 to mp3 for obfuscation. Technique004
 avatar
unknown
javascript
2 years ago
2.4 kB
5
Indexable
The issue here is that in your `layout_strings` function, you are checking if each character is equal to either 'm', 'n', 'M', or 'N', but you are checking this independently for each character. So when 'MN' is passed as the input, the code first encounters the 'M' and correctly generates 'big Mango', but then encounters the 'N' and generates 'small nectarine' since 'N' is not equal to 'm' or 'M'. 

One way to fix this is to modify the code to check for occurrences of 'm' or 'M' followed by 'n' or 'N' and then generate the corresponding output based on that pattern. Here's the modified `layout_strings` function:

```
function layout_strings(input_string) { 
  var output_string = ""; 
  var lowercase = "abcdefghijklmnopqrstuvwxyz"; 
  var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 

  for (var i = 0; i < input_string.length; i++) { 
    var char = input_string.charAt(i); 
    
    if (i < input_string.length - 1) { // Check if there are at least two more characters left in the input
      var next_char = input_string.charAt(i + 1); 
      var mn_pattern = (char == 'm' || char == 'M') && (next_char == 'n' || next_char == 'N'); 
      
      if (mn_pattern) { // if we have a valid pattern ['Mm']['Nn']
        if (char == 'm') {  
          output_string += "small mango, "; 
        } else if (char == 'M') {  
          output_string += "big Mango, "; 
        }
        i++; // increment index to skip next char (N/n) in the pattern 
        continue; // skip rest of the loop body
      }
    } 
    
    // not part of 'MN' pattern, so generate output based on character case
    if (uppercase.indexOf(char) !== -1) { 
      output_string += "big " + char + ", "; 
    } else if (lowercase.indexOf(char) !== -1) { 
      output_string += "small " + char + ", "; 
    }
  } 
  
  output_string = output_string.slice(0, -2); 
  return output_string; 
}
```

The updated code above uses a variable `mn_pattern` to check if the current character 'char' is 'M' or 'm' and the next character 'next_char' is 'N' or 'n' (indicating the pattern 'MN' or 'mN'). If that pattern is found, then the code generates the corresponding output ('big Mango' or 'small mango' respectively) and increments the index 'i' to skip the next character before continuing with the loop. 

With these changes, passing 'MN' should now produce 'big Mango, big Nectarine' as expected.
Editor is loading...