daily pastebin goal
72%
SHARE
TWEET

Untitled

social1986 Jan 23rd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     let buttons = document.getElementsByTagName('button');
  3.     buttons[0].addEventListener('click', encode);
  4.     buttons[1].addEventListener('click', decode);
  5.  
  6.     let inputFields = document.getElementsByTagName('textarea');
  7.     let encodeInputField = inputFields[0];
  8.     let decodeInputField = inputFields[1];
  9.  
  10.     function encode() {
  11.         let message = encodeInputField.value;
  12.  
  13.         if (message) {
  14.             let encodedMessage = '';
  15.  
  16.             for (var i = 0; i < message.length; i++) {
  17.                 let currentAsciiCode =  message[i].charCodeAt();
  18.                 let currentSymbol = String.fromCharCode((currentAsciiCode + 1));
  19.                 encodedMessage += currentSymbol;
  20.               }
  21.             decodeInputField.value = encodedMessage;
  22.             encodeInputField.value = '';
  23.         }
  24.     }
  25.  
  26.     function decode() {
  27.         let message  = decodeInputField.value;
  28.  
  29.         if (message) {
  30.             let decodedMeesage = '';
  31.  
  32.             for (var i = 0; i < message.length; i++) {
  33.                 let currentAsciiCode =  message[i].charCodeAt();
  34.                 let currentSymbol = String.fromCharCode((currentAsciiCode - 1));
  35.                 decodedMeesage += currentSymbol;
  36.               }
  37.             decodeInputField.value = decodedMeesage;
  38.         }
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top