repl.it
@ActionJack/

Cryptogram Generator

JavaScript

Takes a string and turns it into a cryptogram with a randomly-generated substitution cipher.

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var alphabet= "abcdefghijklmnopqrstuvwxyz";
function generateCipher(){
  let result = alphabet.split("");
  //console.log(result)
  for(let i = 0; i < result.length; i++){
    var switchplace= Math.floor(Math.random() * result.length);
    var temp = result[i];
    result[i]= result[switchplace];
    result[switchplace]= temp;
  }
  return result.join("");
}

function cryptogram(str){
  let cipher= generateCipher();
  let result= "";
  for(let i=0; i<str.length; i++){
    let char= str[i].toLowerCase();
    if(cipher.indexOf(char)>=0){
      result+=(cipher[alphabet.indexOf(char)]);
    }
    else{
      result+=char
    }
  }
  return result;
}

cryptogram("PARTY in town tonight brah!!! Will you be there, or would you rather be square?")
Native Browser JavaScript
?