Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function songEncryption(input) {
- let pattern = /^([A-Z][a-z' ]+):([A-Z ]+)$/g;
- while ((line = input.shift()) !== 'end') {
- if (line.match(pattern)) {
- let fordecription = line.match(pattern)[0];
- let key = fordecription.split(':')[0].length;
- let decrepted = fordecription.split('').map(el => {
- if (el.charCodeAt() >= 65 && el.charCodeAt() <= 90) {
- return String.fromCharCode(65 + ((el.charCodeAt() + key) % 65) % 26);
- } else if (el.charCodeAt() >= 97 && el.charCodeAt() <= 122) {
- return String.fromCharCode(97 + ((el.charCodeAt() + key) % 97) % 26);
- } else if (el.charCodeAt() === 58) {
- return String.fromCharCode(64);
- } else {
- return el
- }
- }).join('');
- console.log(`Successful encryption: ${decrepted}`);
- } else {
- console.log('Invalid input!')
- }
- }
- }
- songEncryption(['Eminem:VENOM',
- 'Linkin park:NUMB',
- 'Drake:NONSTOP',
- 'Adele:HELLO',
- 'end']);
- songEncryption(['Michael Jackson:ANOTHER PART OF ME',
- 'Adele:ONE AND ONLY',
- 'Guns n\'roses:NOVEMBER RAIN',
- 'Christina Aguilera: HuRt',
- 'end']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement