
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Decrypting source message from a code based on some algorithm in JavaScript
Problem
We are required to write a JavaScript function that takes in a decrypted message and returns its source message.
All we know is the algorithm used to encrypt that message.
And the algorithm is −
- Reverse the message string.
- Replace every letter with its ASCII code in quotes (A to '65', h to '104' and so on).
- Insert digits and spaces as is.
Example
Following is the code −
const str = '12 hello world 30'; const decryptString = (str = '') => { const alpha = 'abcdefghijklmnopqrstuvwxyz'; let res = ''; for(let i = str.length - 1; i >= 0; i--){ const el = str[i]; if(alpha.includes(el.toLowerCase())){ res += `'${el.charCodeAt(0)}'`; }else{ res += el; }; }; return res; }; console.log(decryptString(str));
Output
Following is the console output −
03 '100''108''114''111''119' '111''108''108''101''104' 21
- Related Questions & Answers
- Encrypting a string based on an algorithm in JavaScript
- Encrypting a string based on an algorithm using JavaScript
- Calculating value of a sequence based on some input using JavaScript
- Delete only some rows from a table based on a condition in MySQL
- Constructing 2-D array based on some constraints in JavaScript
- How to retrieve source code from Python objects?
- Installing MySQL from source on linux
- How Does a Message Authentication Code Work?
- How can I export values based on some conditions from MySQL table into a file?
- How can you select data from a table based on some criteria using MySQL in Python?
- Display a message on console while focusing on input type in JavaScript?
- Rearrange the given source code in C++
- Change string based on a condition - JavaScript
- Returning acronym based on a string in JavaScript
- Calculate average from JSON data based on multiple filters JavaScript
Advertisements