SHARE
TWEET

Untitled

a guest Jun 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function encodeAndDecodeMessages() {
  2.     let firstTextArea = document.getElementsByTagName('textarea')[0];
  3.     let secondTextArea = document.getElementsByTagName('textarea')[1];
  4.  
  5.     let encodeButton = document.getElementsByTagName('button')[0];
  6.     let decodeButton = document.getElementsByTagName('button')[1];
  7.  
  8.     encodeButton.addEventListener('click', () => {
  9.  
  10.         let input = firstTextArea.value;
  11.         let encodedText = '';
  12.  
  13.         for (let i = 0; i < input.length; i++) {
  14.             encodedText += String.fromCharCode(input.charCodeAt(i) + 1);
  15.  
  16.         }
  17.  
  18.         firstTextArea.value = '';
  19.         secondTextArea.value = encodedText;
  20.     });
  21.  
  22.     decodeButton.addEventListener('click', function () {
  23.  
  24.         let input = secondTextArea.value;
  25.         let decodeText = '';
  26.  
  27.         for (let i = 0; i < input.length; i++) {
  28.             decodeText += String.fromCharCode(input.charCodeAt(i) - 1);
  29.         }
  30.  
  31.         secondTextArea.value = decodeText;
  32.     });
  33. }
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