Ejemplo n.º 1
0
def first_response(update, context):
    text = update.message.text
    if text == 'Enigma':
        context.user_data['cipher'] = text
        update.message.reply_text("Что делать будем?", reply_markup=cip)
    elif text == 'Шифр Цезаря':
        context.user_data['cipher'] = text
        update.message.reply_text("Что делать будем?", reply_markup=cip)
    elif text == 'Braille':
        context.user_data['cipher'] = text
        update.message.reply_text("Что делать будем?", reply_markup=cip)
    elif text == 'Двоичный код':
        context.user_data['cipher'] = text
        update.message.reply_text("Что делать будем?", reply_markup=cip)
    elif text == 'Morse':
        context.user_data['cipher'] = text
        update.message.reply_text("Что делать будем?", reply_markup=cip)
    elif text == 'return':
        close_keyboard(update, context)
        return ConversationHandler.END
    elif text == 'history':
        update.message.reply_text(print_history(context.user_data['id']))
        return 1
    else:
        update.message.reply_text("Чего не умею, того не умею.")
    return 4
Ejemplo n.º 2
0
def second_response(update, context):
    text = update.message.text
    if text == 'return':
        update.message.reply_text('OK', reply_markup=markup)
        return 1
    elif text == 'history':
        update.message.reply_text(print_history(context.user_data['id']))
        return 4
    elif text.lower() == 'Зашифровать'.lower():
        if context.user_data['cipher'].lower() == 'Enigma'.lower():
            update.message.reply_text(
                "Для начала нужно ввести 3 ключя для роторов,\n"
                " а затем через '-' ввести текст на англиском,\n"
                " состояший только из букв и пробелов.\n"
                " Пример: ABC-Hello World.",
                reply_markup=com_return)
            return 5
        elif context.user_data['cipher'].lower() == 'Двоичный код'.lower():
            answer = """Ввод: <текст>"""
            update.message.reply_text(answer, reply_markup=com_return)
        elif context.user_data['cipher'].lower() == 'Шифр Цезаря'.lower():
            answer = "Ввод: <ключ>-<текст>\n" \
                     "Ключ-Одно число от 1 до 26."
            update.message.reply_text(answer, reply_markup=com_return)
        elif context.user_data['cipher'].lower() == 'Morse'.lower():
            answer = "Ввод: <текст>\n" \
                     "Текст только на английском"
            update.message.reply_text(answer, reply_markup=com_return)
        elif context.user_data['cipher'].lower() == 'Braille'.lower():
            answer = "Ввод: <текст>\n" \
                     "Текст только на английском, без цифр"
            update.message.reply_text(answer, reply_markup=com_return)
        return 2
    elif text.lower() == 'Расшифровать'.lower():
        if context.user_data['cipher'].lower() == 'Enigma'.lower():
            update.message.reply_text(
                "Для начала нужно ввести 3 ключи для роторов,\n"
                "которые были использованный для шифровки,"
                "затем через '-' ввести шифр только на англиском,\n"
                "состояший только из букв и пробелов.\n"
                "Пример: ABC-FPXKE HWZEQ.",
                reply_markup=com_return)
            return 5
        elif context.user_data['cipher'].lower() == 'Двоичный код'.lower():
            answer = """Ввод: <код>"""
            update.message.reply_text(answer, reply_markup=com_return)
        elif context.user_data['cipher'].lower() == 'Шифр Цезаря'.lower():
            answer = "Ввод: <ключ>-<шифр>\n" \
                     "Ключ-Число, которое использовалось для шифровки."
            update.message.reply_text(answer, reply_markup=com_return)
        elif context.user_data['cipher'].lower() == 'Morse'.lower():
            answer = """Ввод: <шифр>"""
            update.message.reply_text(answer, reply_markup=com_return)
        elif context.user_data['cipher'].lower() == 'Braille'.lower():
            answer = "Ввод: <шифр>"
            update.message.reply_text(answer, reply_markup=com_return)
        return 3
    return 4
Ejemplo n.º 3
0
def decrypt_response(update, context):
    text = update.message.text
    db_text = text
    if text == 'return':
        update.message.reply_text('OK', reply_markup=cip)
        return 4
    elif text == 'history':
        update.message.reply_text(print_history(context.user_data['id']))
        return 3
    if context.user_data['cipher'].lower() == 'Двоичный код'.lower():
        try:
            cipher_text = from_cipher(text)
        except Exception:
            update.message.reply_text('Вы точно ввели код')
    elif context.user_data['cipher'].lower() == 'Morse'.lower():
        try:
            cipher_text = demorse(text)
            if len(cipher_text) == 0:
                update.message.reply_text('Ошибка в типе введенных данных.')
                return 3
            elif cipher_text is None:
                update.message.reply_text('Ошибка в типе введенных данных.')
                return 3
        except Exception:
            update.message.reply_text('Ошибка в типе введенных данных.')
    elif context.user_data['cipher'].lower() == 'Braille'.lower():
        try:
            cipher_text = debraille_code(text)
            if len(cipher_text) == 0:
                update.message.reply_text('Ошибка в типе введенных данных.')
                return 3
            elif cipher_text is None:
                update.message.reply_text('Ошибка в типе введенных данных.')
                return 3
        except Exception:
            update.message.reply_text('Ошибка в типе введенных данных.')
    elif context.user_data['cipher'].lower() == 'Шифр Цезаря'.lower():
        try:
            key, text = text.split('-')[0], text.split('-')[1]
            if int(key) > 26 or int(key) < 1:
                update.message.reply_text('Неправильный ключ')
                return 3
            cipher_text = caesars_cipher(int(key) * -1, text)
            if len(cipher_text) == 0:
                update.message.reply_text('Ошибка в типе введенных данных.')
                return 3
        except Exception:
            update.message.reply_text(
                'Вы вели слишком много ключей\n'
                'или ошиблись в типе данных, ввели посторонние символы!')
    create_history(context.user_data['id'], db_text, f"{cipher_text}")
    update.message.reply_text(f"{cipher_text}")
    return 3
Ejemplo n.º 4
0
def enigma_response(update, context):
    text = update.message.text
    if text == 'return':
        update.message.reply_text('OK', reply_markup=cip)
        return 4
    elif text == 'history':
        update.message.reply_text(print_history(context.user_data['id']))
        return 5
    else:
        try:
            enigma = enigma_code(text)
            create_history(context.user_data['id'], text, f"{''.join(enigma)}")
        except Exception:
            update.message.reply_text(
                'Вы вели слишком много ключей\n'
                'или ошиблись в типе данных, ввели посторонние символы!')
            return 5
        update.message.reply_text(f"{''.join(enigma)}")
    return 5