Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Code :

C#
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?
Posted
Comments
Sunasara Imdadhusen 6-May-14 8:20am    
You have to update your logic according to your requirement, as per your requirement what you want exactly it's not clear.

1 solution

Change replaceAll to replace:
string = string.replace(old_string, replace_array[i]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900