# Convert byte data to character data

Page 1 of 1

## 1 Replies - 729 Views - Last Post: 25 August 2013 - 12:02 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=327611&amp;s=b980fcf0906cd0e1062ea5080a5d2bed&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 jcwiekalo

Reputation: 0
• Posts: 2
• Joined: 24-August 13

# Convert byte data to character data

Posted 24 August 2013 - 11:23 AM

I'm working on solving a set of programming exercises from overthewire.org for fun and programming-related experience. The first problem has the following information to solve it:

1. connect to a server/port
3. sum the integers
4. send sum of integers to server

```
#!/usr/bin/python

"""
overthewire.org vortex lab #1 solution in Python
"""

# imports

import socket

# variables

host = "vortex.labs.overthewire.org"
port = 5842
rcvbytes = 4
size = 1024

# TASK 1 - create socket connection

sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sckt.connect((host, port))

data = sckt.recv(16)

# convert data to integer values

print("converted values:", list(data))

# TASK 3 - sum all array values

arraytotal = sum(data)
print("total of integers:", arraytotal)

# TASK 4 - send results to server

sckt.send(b'arraytotal')

data = sckt.recv(size)

# close socket

sckt.close()

# print data

```

results from running code:

D:\myCode>python myvortex2.py

converted values: [176, 48, 101, 58]
total of integers: 383
username/password: [226, 67, 27, 79, 142, 245, 216, 4, 194, 212, 9, 46]

=====
I (think) I've successfully completed tasks 1 - 4 and have received the values associated with TASK 5, but can't convert it to letters/numbers to sign in with it.

Is This A Good Question/Topic? 0

## Replies To: Convert byte data to character data

### #2 sillygod

Reputation: 0
• Posts: 14
• Joined: 23-January 13

## Re: Convert byte data to character data

Posted 25 August 2013 - 12:02 AM

well... I think first, you should post where the question comes from because I can't figure out what's the problem you encoutner. I spent some time and then find it.
However, I still can't totally understand what it say after read the question. Maybe I need to improve my english...
Whatever, I finally solve the question. here is my code,

```import socket

st = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
st.connect(('vortex.labs.overthewire.org', 5842))
ans = sum([  int.from_bytes(st.recv(4), byteorder='little') for i in range(4)])

st.sendall(ans.to_bytes(ans.bit_length()//8+1, byteorder='little'))