N
N
niggaedition2018-09-17 18:35:54
Python
niggaedition, 2018-09-17 18:35:54

How to make a command to encrypt a message?

I am developing a bot. I want to make commands like these:
bot cipher *text to be encrypted* in base64
bot decrypt *encrypted text*
I work with the vk_api library for peton.
I tried to do it my way:

import base64
dhistory = vk.messages.getHistory(peer_id=peerid,count=1,)
text = dhistory['items'][0]['text']
dhistory = "бот шифр "
b64 = text.split(' ')[-1]
      if text == "бот шифр " + b64:
         b64 = text.split(' ')[-1]
         s64 = base64.b64encode(b64)
         vk.messages.send(peer_id=peerid,message=s64)

I scribbled it, and xs how.
everything would be fine except for one, but
the error "a bytes-like object is required, not 'str'" pops up in the console,
can there be another way to use it, or can I fix this one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
igorzakhar, 2018-09-17
@niggaedition

...
s64 = base64.b64encode(b64)
...

The b64 argument must be "bytes-like object". Your b64 is a string.
b64 = text.split(' ')[-1]
b64_to_bytes = str.encode(b64)
s64 = base64.b64encode(b64_to_bytes)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question