Code :
String.prototype.replaceAll = function(search, replace){
if(!replace){
return this;
}
return this.replace(new RegExp('[' + search + ']', 'g'), replace);
};
function encrypt(){
var string = prompt("String to Encrypt : ");
replace_array = ["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", "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"];
string = string.replaceAll("/", "53/");
for (var i = 0; i < 52; i++){
if (i < 9) {
new_string = "0" + String(i + 1);
} else {
new_string = String(i + 1);
}
string = string.replaceAll(replace_array[i], new_string + "/");
}
alert(string);
}
function decrypt(){
var string = prompt("String to Decrypt : ");
replace_array = ["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", "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"];
for (var i = 0; i < 52; i++){
if (i < 9) {
old_string = "0" + String(i + 1);
} else {
old_string = String(i + 1);
}
old_string = old_string + "/";
string = string.replaceAll(old_string, replace_array[i]);
}
alert(string);
}
When I
decrypt()
string `01/02/03/` I want to get `abc` instead of aaaabaaca.
What can I do?