• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Занятие 2. Conditions

Difficulty level:

Task«Cryptographic analyzer»

you & mdash; The younger assistant in the cryptography department. Your senior colleague is engaged in the decoding of an important message written in English using frequency analysis. He has already determined what symbol in the cipher jack is most often found. Now he needs to check a few hypotheses about what letter of the English alphabet this symbol corresponds to.

rn

your task & mdash; Write a program that will help to quickly assess the plausibility of the hypothesis. The program should request an encrypted message (it is necessary for context, but it is not required to analyze it) and the alleged letter-key (the one, into which, according to the hypothesis, the most frequent symbol is expanded).

rn

Based on the common ones; Knowledge about the frequency of letters in English, the program should make a verdict about the probability of the key according to the following rules:

rn rn
  • 'E' , this is the most likely option, since 'E' & Mdash; The most common letter in English.
  • rn
  • if the key & mdash; One of the other frequent vowels ( 'a' a ', & nbsp; ' o ', & nbsp; ' i '), then this is a probable option.
  • rn
  • if the key & mdash; One of the rarest letters ( 'z' , & nbsp; 'q' , & nbsp; 'j' , & nbsp; '' x '), then this is unlikely Option.
  • rn
  • in all other cases (other consonants and vowels) is considered dubious.
  • rn

    the program should display one of four assessments: & laquo; the most likely key. & raquo; & laquo; probable key. & raquo;, & laquo; unlikely key. & raquo; or & laquo; dubious key. & raquo;.

    Input format


    Output format

    Example

    Input

    xli getvi csyph xsve!
    e

    Output

    The most likely key.

    Hint

    There will be no clue here, decide for yourself!

    main.py
    Test 1
    Test 2
    Test 3
    Test 4
    Test 5
    Test 6
    Test 7
    Test 8
    Test 9
    Test 10
    Developer’s solution
    # Программа запрашивает зашифрованное сообщение.
    # Оно не используется в логике, но является частью условия задачи.
    encrypted_message = input()
    
    # Программа запрашивает предполагаемый ключ — одну букву.
    # Это главный входной параметр, который будет анализироваться.
    key_char = input()
    
    # Проверяем, является ли предложенный ключ буквой 'E'.
    # Это основное и самое сильное условие.
    if key_char == 'E':
        # Если да, выводим сообщение о наибольшей вероятности.
        print("Наиболее вероятный ключ.")
    
    # Если ключ не 'E', проверяем, является ли он одной из других частых гласных.
    # Используем несколько условий 'or' для проверки вхождения в группу.
    elif key_char == 'A' or key_char == 'O' or key_char == 'I':
        # Если да, выводим сообщение о вероятности.
        print("Вероятный ключ.")
    
    # Если предыдущие условия не выполнились, проверяем, не является ли ключ редкой буквой.
    elif key_char == 'Z' or key_char == 'Q' or key_char == 'J' or key_char == 'X':
        # Если да, выводим сообщение о малой вероятности.
        print("Маловероятный ключ.")
    
    # Если ни одно из вышеперечисленных условий не сработало,
    # значит, это любой другой символ (частая согласная и т.д.).
    else:
        # Выводим сообщение о сомнительности ключа.
        print("Сомнительный ключ.")

    🎉 Congratulations! 🎉

    You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

    AD

    Advertisement

    red-snake blue-snake green-snake

    Running your code...

    Помощник ИИ

    Привет! Я твой помощник по программированию. Задавай любые вопросы по Python, я могу рассказать о функциях, методах, обьяснить то, что тебе не понятно, а так же о текущей задаче!