#๐ How can I make input() take bytes for .decode() to work?
56 messages ยท Page 1 of 1 (latest)
@fierce crow
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
import base64
a = int(input("Enter how many times you want your code encrypted/decrypted: "))
type = input("Encryption ('a') or decryption ('b'): ")
random_code = input("Enter code: ")
def encode(a):
global random_code
global d
for i in range(0,a):
enc = random_code.encode(encoding="utf-32-le")
enc1 = base64.a85encode(enc)
enc2 = base64.b16encode(enc1)
enc3 = base64.b32encode(enc2)
d = base64.b64encode(enc3)
def decode(a):
global random_code
global d
for i in range(0,a):
dec = random_code.decode(encoding="utf-32-le")
dec1 = base64.a85decode(dec)
dec2 = base64.b16decode(dec1)
dec3 = base64.b32encode(dec2)
d = base64.b64decode(dec3)
if type == "a":
encode(a)
elif type == "b":
decode(a)
print(d)
this is my entire program
it gets mad because it thinks im inputting a str into random_code.decode(encoding="utf-32-le")
which im not
is there anything like str(input()) but for bytes?
You can encode the string and then run the function on it
I meant the str.encode() method
!e
print("hello ะถะถะถ world".encode("utf-8"))
:white_check_mark: Your 3.12 eval job has completed with return code 0.
b'hello \xd0\xb6\xd0\xb6\xd0\xb6 world'
this is a case where type hints might help
they'd help you remember if your functions take and return strings or bytes
that's fine, as long as you're consistent
If you encoded the string as ```py
s = originasl
s = b64encode(s)
s = a85encode(s)
a. `raw = a85decode(b64decode(s))`
b. `raw = b64decode(a85decode(s))`
b
im really new to python (less than 1 month) so im sorry if thats the wrong answer
wait a would make more sense
because a85 went last before so it should go first
exactly
there was an encode in the decodes
if you'd like, I can show you how I'd do it.
sure im trying to learn
I think they key thing is: when you decrypt, you need to call various decode functions, and in the reverse order.
it means "call the function f, passing it enc, then assign the result to enc"
works for me. Are you running exactly the code I pasted?
i think so yeah
try doing a double encryption with something like "abcdefghijklmnopqrstuvwxyz"
I don't know what you mean by "doing a double encryption", but I see what you mean
This is better. It doesn't use the windows encoding
(echo 3; echo b; echo R05C...OU0Q=) | python3 gerry.py
Enter how many times you want your code encrypted/decrypted: Encryption ('a') or decryption ('b'): Enter code: abcdefghijklmnopqrstuvwxyz
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.