Decrypt the String according to given algorithm | JavaScript implementation of the approach ; Function that returns ( num % 26 ) ; Initialize result ; One by one process all digits of ' num ' ; Function to return the decrypted String ; To store the final decrypted answer ; One by one check for each character if it is a numeric character ; Modulo the number found in the String by 26 ; Driver code ; Print the decrypted string
let MOD = 26 ; function modulo_by_26 ( num ) { let res = 0 ; for ( let i = 0 ; i < num . length ; i ++ ) { res = ( ( res * 10 + num [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) % MOD ) ; } return res ; } function decrypt_message ( s ) { let decrypted_str = " " ; let num_found_so_far = " " ; for ( let i = 0 ; i < s . length ; ++ i ) { if ( s [ i ] . charCodeAt ( 0 ) >= ' ' . charCodeAt ( 0 ) && s [ i ] . charCodeAt ( 0 ) <= ' ' . charCodeAt ( 0 ) ) { num_found_so_far += s [ i ] ; } else if ( num_found_so_far . length > 0 ) { decrypted_str += String . fromCharCode ( ' ' . charCodeAt ( 0 ) + modulo_by_26 ( num_found_so_far ) ) ; num_found_so_far = " " ; } } if ( num_found_so_far . length > 0 ) { decrypted_str += String . fromCharCode ( ' ' . charCodeAt ( 0 ) + modulo_by_26 ( num_found_so_far ) ) ; } return decrypted_str ; } let s = " " ; document . write ( decrypt_message ( s ) ) ;