#đź”’ Converting to 8bit ASCII
41 messages · Page 1 of 1 (latest)
@short tendon
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.
Did you try it?
ascii is kinda 7 bit though. what exactly do you want to achieve with that?
yes, but I’m not sure if it’s 8bit or not
This is my task
I need to perform an XOR
i need to perform an xor between binary of 8 bit ascii of attack at dawn and the binary of the given hex
then you need to encode it. and xor byte by byte.
what does encode it mean?
"attack at dawn" is a unicode string. encoding means converting it to bytes using some encoding or charset. e.g. you could use the ascii encoding for that
!e
text = "attack at dawn"
encoded = text.encode('ascii')
print(encoded)
print(text[0], '=', encoded[0])
print(text[1], '=', encoded[1])
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | b'attack at dawn'
002 | a = 97
003 | t = 116
If I were to do it manually, I’ll need to check the ASCII of each character and write it each block of 8 bits right?
in binary
if you want to write down the bits, then yes. ascii only covers the lower 7 bit of a byte, but you can just add an 8th bit to make it 8 bits.
(the 8th bit would be a 0)
so each byte i can put an extra 0 ?
same for each byte right?
or more, depending on how many bits the ascii number occupies. e.g. a space has ascii 32, and only needs 6 bits.
makes sense essentially add fillers to make it 8 bit to store each character
(the thing with extra zeros at the higher places is really the same with any other number system.
The decimal number 185 is the same as 0185 or 0000000185)
yep
How do I acheive this in python?
Can I do XOR in other bases?
Maybe i can convert ASCII to hex and then do xor in hex
xor is a bitwise operator
My final answer has to be in hex
decimal, binary, and hex are just different ways to express the same number, you perform operations on numbers not bases
if you do it in python, you only have to make sure it's an integer type... the python xor operator does it on bitwise level... and the result will be an integer, that you can convert to a hex string using the hex() function.
Yes, indeed
I see
in the case of bitwise operators, it is easiest to do it by hand when you write out the number in binary, then you can convert that number to however you want to display it afterwards, i.e. hex
in a program, just deal with numbers without regard for base until you eventually need to display it
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.