Y
Y
YOKARAMANE2021-10-26 23:43:38
Python
YOKARAMANE, 2021-10-26 23:43:38

How to implement Caesar cipher in Telegram bot?

/del /del /del /del /del /del /del /del /del

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ananchenko, 2021-10-27
@YOKARAMANE

def get_arg(arg):
    return arg.split()[1:]

@bot.message_handler(commands = ['encrypt'])
def msg_encrypt(message):
    arg = get_arg(message.text)
    if len(arg) >= 2:
        bot.reply_to(message,f"{encrypt(arg[0:-1], arg[-1])}")
    else:
        bot.reply_to(message,'Вы не указали параметры шифрования!\nПример: `/encrypt {Ваше сверх секретное сообщение} {ключ}`', parse_mode = 'Markdown')

The code is quite crude, but I made a base for you, just modify it, I think you can handle the decryption
And here I already see my mistakes like encrypt will receive a sheet and not a string, but I think you can make the function of transforming a sheet into a string, if you are too lazy, write it off he's only a couple of lines there, but I'm a lazy person, I was too lazy to look for where he is

V
Vindicar, 2021-10-27
@Vindicar

And what about input()? This function only deals with input from the console.
Same with print(), it's purely console output.
The simplest way, if the bot has only this purpose and no other, is not to bathe with commands, but simply to respond to each incoming message in encrypted form. This will be a modification of a simple echo bot that you took as a basis. The message parameter is passed to you in the handler, deal with it.
Otherwise, you will need to parse the incoming message (tear off the command from the beginning), and encrypt it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question