Decrypt the String according to given algorithm | Java 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
import java . util . * ; class GFG { static int MOD = 26 ; static int modulo_by_26 ( String num ) { int res = 0 ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) { res = ( ( res * 10 + ( int ) num . charAt ( i ) - '0' ) % MOD ) ; } return res ; } static String decrypt_message ( String s ) { String decrypted_str = " " ; String num_found_so_far = " " ; for ( int i = 0 ; i < s . length ( ) ; ++ i ) { if ( s . charAt ( i ) >= '0' && s . charAt ( i ) <= '9' ) { num_found_so_far += s . charAt ( i ) ; } else if ( num_found_so_far . length ( ) > 0 ) { decrypted_str += ( char ) ( ' a ' + modulo_by_26 ( num_found_so_far ) ) ; num_found_so_far = " " ; } } if ( num_found_so_far . length ( ) > 0 ) { decrypted_str += ( char ) ( ' a ' + modulo_by_26 ( num_found_so_far ) ) ; } return decrypted_str ; } public static void main ( String [ ] args ) { String s = "32ytAAcV4ui30hf10hj18" ; System . out . print ( decrypt_message ( s ) ) ; } }