Fundamental Concepts
Bytes Representation
# We can observe its representation
print("Raw Byte:", b'\x00') # Raw byte that is not printable
print("Printable Byte:", b'\x41') # Raw byte but is printed as 'A'
# We can obtain an int value with the position in the 0-255 range
byte1 = b'B'
print("Byte Value:", byte1[0])
# For byte strings, we could do the same with the byte at any position
byte_str = b'flag'
print("String Byte Values:", byte_str[0],byte_str[1],byte_str[2],byte_str[3])
# We can concatenate bytes, or operate on them using their int representation
byte1 = b'\x03'
byte2 = b'\x02'
print("Concatenate:", byte1 + byte2)
print("Result Value:", byte1[0] + byte2[0]) # This return and the result int
print("Result Bytes:", bytes([byte1[0] + byte2[0]])) # This converts the result again in bytes
# As bytes only are in the 0-255 range, we could have errors outside this range
b1 = b'\xf0' # Its value is 240
b2 = b'\x3f' # Its value is 63
add = b1[0] + b2[0] # The result is 303, out of the range
# We can use the modular operator to truncate results in the range
add = add % 256 # Now, the result is b'\x47' which is b'/'
print("Result in range:", bytes([add]))Long Integer Representation
XOR Operation
Properties
Implementation
Last updated