I made a simple desktop app sometime back that is meant to be my own custom plaintext encryption software(yes, I know, a weird project when I was bored). Now I actually need the software working as I see a need to encrypt some of my text based writeups on my laptop. I use ElectronJS framework for my desktop apps.
The problem iβve spotted looking at the code is that the javascript charAt(); method is not accepting my for loop counter as a valid return value and thatβs what I need the code to do. I used alert() to debug this.
Long story short, hereβs the JS code:
<script>
//Function to search and sort plaintext to ciphertext
//const fs = require('fs'); //requiring the filesystem module from nodejs to help us handle files
var plaintext;
var cipherstring = new Array(500);
var newstring;
document.getElementById("Encryptbutton").onclick = () => {
//first we save the plaintext file
var plaintext = document.getElementById("textbox").value; //store value of textbox in plaintext
//fs.writeFile ('text.txt',data, (err) => {
//if (err) throw err;
//}) //this will handle any error writing the file by ignoring it
//plaintext = data; //store the value of the textbox in variable called plaintext
var i;
for (i=0;i=plaintext.length;i++){ //loop to run through plaintext
var x = plaintext.charAt(plaintext.length); //x will hold the positions of characters in the array and return their value.
//alert(i); //testing to see what i returns at this point
//alert(x); //testing to see what x returns at this point
switch (x) { //simple way of testing each character in the array of strings
case "a" || "A":
cipherstring.push("N[β],N[β],E[β]W");
break;
case "b" || "B":
cipherstring.push("N[β]S,N[β·]O,O[β·]S");
break;
case "c" || "C":
cipherstring.push("N[βΆ]S");
break;
case "d" || "D":
cipherstring.push("N[β]S,N[β·]S");
break;
case "e" || "E":
cipherstring.push("E[]");
break;
case "f" || "F":
cipherstring.push("N[β]S,N[β],W[β]O");
break;
case "g" || "G":
cipherstring.push("N[βΆ]S,S[β]O");
break;
case "h" || "H":
cipherstring.push("1N[β]S,E[β]W,3N[β]S");
break;
case "i" || "I":
cipherstring.push("N[β]S");
break;
case "j" || "J":
cipherstring.push("N[β],N[β]S,S[β]");
break;
case "k" || "K":
cipherstring.push("N[β]S,O[β],O[β]");
break;
case "l" || "L":
cipherstring.push("N[β]S,S[β]");
break;
case "m" || "M":
cipherstring.push("N[β]S,N[β]O,3N[β]O,3N[β]S");
break;
case "n" || "N":
cipherstring.push("N[]");
break;
case "o" || "O":
cipherstring.push("O[]");
break;
case "p" || "P":
cipherstring.push("N[β]S,N[β·]O");
break;
case "q" || "Q":
cipherstring.push("N[β·]S,S[β·]N,O[β]");
break;
case "r" || "R":
cipherstring.push("N[β]S,N[β·]O,O[β]");
break;
case "s" || "S":
cipherstring.push("S[]");
break;
case "t" || "T":
cipherstring.push("N[β],N[β]S");
break;
case "u" || "U":
cipherstring.push("N[βΆ]S,S[βΆ]3N");
break;
case "v" || "V":
cipherstring.push("1N[β]S,S[β]3N");
break;
case "w" || "W":
cipherstring.push("W[]");
break;
case "x" || "X":
cipherstring.push("1N[β]3S,1S[β]3N");
break;
case "y" || "Y":
cipherstring.push("1N[β]O,S[β]O,O[β]");
break;
case "z" || "Z":
cipherstring.push("N[β],3N[β]S,1S[β]");
case "0":
cipherstring.push(".0");
break;
case "1":
cipherstring.push(".1");
break;
case "2":
cipherstring.push(".2");
break;
case "3":
cipherstring.push(".3");
break;
case "4":
cipherstring.push(".4");
break;
case "5":
cipherstring.push(".5");
break;
case "6":
cipherstring.push(".6");
break;
case "7":
cipherstring.push(".7");
break;
case "8":
cipherstring.push(".8");
break;
case "9":
cipherstring.push(".9");
break;
default:
cipherstring.push("_symbol_");
} //endswitch
newstring = ":" + cipherstring[i];
} //endforloop
//Finally,we want to display and save the encrypted plaintext as ciphertext
document.getElementById("textArea").value= newstring;
//to call on external javascript files in electron, we use the format;
require('./savefunction.js') //calling my function to save to run here...
}
</script>
Thanks in advance for any help or suggestions on how to rewrite the code.
Regards,
Fejiro