python3
Now enter these commands,
which are immediately executed.
i = 1
print(i, type(i))
j = i + 1
print(j, type(j))
As shown below, i and j are 'int'
objects: integers, so addition works.
a = b'\x01'
print(a, type(a))
b = a + 1
As shown below,
a is a "bytes" object,
and addition is not allowed.
One way to convert bytes to integers
is to select a specific
byte.
Execute these commands:
b = a[0]
print(b, type(b))
c = b + 1
print(c, type(c))
As shown below,
b is a "int" object,
and addition works.
So, to add one to a byte object,
execute these commands:
a = b'\x01'
print(a, type(a))
b = a[0]
print(b, type(b))
c = b + 1
print(c, type(c))
d = bytes([c])
print(d, type(d))
As shown below,
converting the "bytes"
object to an "int" object,
performing the addition,
and converting it back to
"bytes" works.
To exit interactive mode,
execute this command:
exit()
HELLO
In a text editor, make
this program:
with open("infile", "rb") as f:
byte = f.read(1)
while byte != b"":
print(byte)
byte = f.read(1)
As shown below,
this program reads the file
one byte at a time.
In a text editor, make
this program:
with open("infile", "rb") as f:
with open("outfile", "wb") as g:
byte = f.read(1)
while byte != b"":
print(byte)
g.write(byte)
byte = f.read(1)
As shown below,
this program copies
infile to outfile.
Flag VP 110.1: Eights (5)
Download this file:https://samsclass.info/124/proj14/VP110-1To download that file on Debian, execute these commands:Count the number of '\x08' bytes. That's the flag.
sudo apt update sudo apt install wget -y wget https://samsclass.info/124/proj14/VP110-1
Flag VP 110.2: Adding Files (10)
Download these two files:https://samsclass.info/124/proj14/VP110-2aAdd the bytes in the two files together to construct the flag. For example, if the first file contains b'\x40' and the second contains b'\x01', the result is b'\x41', or "A".
https://samsclass.info/124/proj14/VP110-2b
Flag VP 110.3: Adding Files (10)
Download these two files:https://samsclass.info/124/proj14/VP110-3aAdd the bytes in the two files together to construct a new file named VP110-3-flag.png. Open that file in an image viewer to see the flag.
https://samsclass.info/124/proj14/VP110-3b