Decrypt the String according to given algorithm | Python3 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
MOD = 26 NEW_LINE def modulo_by_26 ( num ) : NEW_LINE INDENT res = 0 NEW_LINE DEDENT ' NEW_LINE INDENT for i in range ( len ( num ) ) : NEW_LINE INDENT res = ( ( res * 10 + ord ( num [ i ] ) - ord ( '0' ) ) % MOD ) NEW_LINE DEDENT return res NEW_LINE DEDENT def decrypt_message ( s ) : NEW_LINE INDENT decrypted_str = " " NEW_LINE num_found_so_far = " " NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( s [ i ] >= '0' and s [ i ] <= '9' ) : NEW_LINE INDENT num_found_so_far += s [ i ] NEW_LINE DEDENT elif ( len ( num_found_so_far ) > 0 ) : NEW_LINE INDENT decrypted_str += chr ( ord ( ' a ' ) + ( modulo_by_26 ( num_found_so_far ) ) ) NEW_LINE num_found_so_far = " " NEW_LINE DEDENT DEDENT if ( len ( num_found_so_far ) > 0 ) : NEW_LINE INDENT decrypted_str += chr ( ord ( ' a ' ) + ( modulo_by_26 ( num_found_so_far ) ) ) NEW_LINE DEDENT return decrypted_str NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = "32ytAAcV4ui30hf10hj18" NEW_LINE print ( decrypt_message ( s ) ) NEW_LINE DEDENT