Skip to content

Instantly share code, notes, and snippets.

@gchristofferson
Last active April 12, 2018 06:47
Show Gist options
  • Save gchristofferson/8f7d13043c212ee2611e42bf575d8a42 to your computer and use it in GitHub Desktop.
Save gchristofferson/8f7d13043c212ee2611e42bf575d8a42 to your computer and use it in GitHub Desktop.
//I have to charCodeAt str i indexOf then add 13. then string from charCode using new number?
function rot13(str) { // LBH QVQ VG!
var array = str.split(" ");
var key = ["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"];
var key1 = {
"A": [0],
"B": [1],
"C": [2],
"D": [3],
"E": [4],
"F": [5],
"G": [6],
"H": [7],
"I": [8],
"J": [9],
"K": [10],
"L": [11],
"M": [12],
"N": [13],
"O": [14],
"P": [15],
"Q": [42],
"R": [43],
"S": [44],
"T": [45],
"U": [46],
"V": [47],
"W": [48],
"X": [49],
"Y": [50],
"Z": [51]
};
// var count = 0;
// while(count < 14){
// key = key.concat(key);
// count++;
// }
var newArray=[];
for(i=0;i<str.length;i++){
for(j=0;j<key.length;j++){
if(str[i] == key[j]){
if(key.indexOf(key[j])<13){
var index = key.indexOf(key[j])+13;
newArray.push(key[index]);
}
else {
var index =
}
// str[i] = key[index];
// return key[index];
// return key[index];
}
}
}
// var newArray = array.join(" ");
// return str[0];
// return key.indexOf("A");
return newArray;
}
// Change the inputs below to test
rot13("NERR PBQR PNZC");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment