
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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 Articles
- Encrypting a string based on an algorithm in JavaScript
- Encrypting a string based on an algorithm using JavaScript
- Constructing 2-D array based on some constraints in 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
- How to retrieve source code from Python objects?
- Read the Source Code of Shell Commands on Linux
- How Does a Message Authentication Code Work?
- Display a message on console while focusing on input type in JavaScript?
- Hashed Message Authentication Code (HMAC)
- How can you select data from a table based on some criteria using MySQL in Python?
- How can I export values based on some conditions from MySQL table into a file?
- Returning acronym based on a string in JavaScript
- Calculate average from JSON data based on multiple filters JavaScript
- Rearrange the given source code in C++

Advertisements