fork(1) download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3.  
  4. function encrypt(plain, cipher, text) {
  5. plain = plain + plain.toUpperCase();
  6. cipher = cipher + cipher.toUpperCase();
  7.  
  8. var newText = '';
  9. for(var i=0; i<text.length; i++) {
  10. var c = text.charAt(i);
  11. var index = plain.indexOf(c);
  12. if(index >= 0 && index < cipher.length) {
  13. newText += cipher.charAt(index);
  14. } else {
  15. newText += c;
  16. }
  17. }
  18. return newText;
  19. }
  20.  
  21. var plainAlphabet = "abcdefghijklmnopqrstuvwxyz";
  22. var cipherAlphabet = "zyxwvutsrqponmlkjihgfedcba";
  23. var text = "Some sensitive text that only humans must be able to read";
  24.  
  25. var encodedText = encrypt(plainAlphabet, cipherAlphabet, text);
  26. process.stdout.write(encodedText);
  27.  
Success #stdin #stdout 0.06s 45736KB
stdin
Standard input is empty
stdout
Hlnv hvmhrgrev gvcg gszg lmob sfnzmh nfhg yv zyov gl ivzw