Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function encodeAndDecodeMessages() {
- function ascii(a) { return a.charCodeAt(0); }
- encodeBtn = document.querySelector("#main > div:nth-child(1) > button");
- dencodeBtn = document.querySelector("#main > div:nth-child(2) > button");
- encodeBtn.addEventListener('click', encodeMessages);
- dencodeBtn.addEventListener('click', decodeMessages);
- function encodeMessages() {
- let theText = document.querySelector("#main > div:nth-child(1) > textarea").value;
- let encodedMessage = '';
- for (let i = 0; i < theText.length; i++) {
- encodedMessage += String.fromCharCode(ascii(`${theText[i]}`) + 1);
- }
- document.querySelector("#main > div:nth-child(1) > textarea").value="";
- document.querySelector("#main > div:nth-child(2) > textarea").value = encodedMessage ;
- }
- function decodeMessages() {
- let theText = document.querySelector("#main > div:nth-child(2) > textarea").value;
- let decodedMessage = '';
- for (let i = 0; i < theText.length; i++) {
- decodedMessage += String.fromCharCode(ascii(`${theText[i]}`) - 1);
- }
- document.querySelector("#main > div:nth-child(2) > textarea").value = decodedMessage ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement