I just started learning python and I thought it would be good practise to play a CTF and make “get flag” scripts in order to learn the different modules. I am stuck on a challenge that makes me connect to a server and then just prompts me with some octal bytes that I need to somehow convert to ascii characters using python. I’ve googled “converting octal bytes to ascii characters” for about 2 hours.. Seems like no page shows how to do that, everything just tells me how to convert normal strings “Hello world” to octal “110 145 154 154 157 040 127 157 162 154 144”. How can I achieve the exact opposite using a python script?
Asked
Active
Viewed 4,876 times
1
-
What is CTF in your context? What is an octal byte? Is it a byte or a character string containing up to 3 numerical ASCII codes? – Mad Physicist Sep 29 '19 at 12:57
-
[Octal to number](https://stackoverflow.com/a/18806794/243245), [number to char](https://stackoverflow.com/a/3673447/243245) – Rup Sep 29 '19 at 13:00
-
Search "converting octal bytes to ascii characters **Python**". The results are more promising – Mad Physicist Sep 29 '19 at 13:01
1 Answers
5
You will need to convert every octal to a number, then convert the number to a char.
Here an example:
def octal_to_str(octal_str):
'''
It takes an octal string and return a string
:octal_str: octal str like "110 145 154"
'''
str_converted = ""
for octal_char in octal_str.split(" "):
str_converted += chr(int(octal_char, 8))
return str_converted
print(octal_to_str("110 145 154 154 157 040 127 157 162 154 144"))

Ankirama
- 498
- 4
- 14