These examples illustrate 1-byte keys and their hexadecimal (hex) representations. Each key is shown as a byte (b''
) with a specific value, followed by its hex representation (h
). Let's break down each one:
- Byte Representation:
b'\x12'
indicates a byte with the hexadecimal value of12
. The\x
prefix is used in Python byte literals to specify the following two characters as a hex value. - Hex Representation:
12
is the direct hexadecimal notation of the byte's value, showing that this byte's value is18
in decimal (1 * 16^1 + 2 * 16^0 = 18).
- Byte Representation:
b'g'
represents the ASCII characterg
as a byte. In ASCII,g
corresponds to the decimal value103
. - Hex Representation:
67
is the hexadecimal equivalent of the decimal103
(6 * 16^1 + 7 * 16^0 = 103
). This demonstrates how textual (ASCII) data is represented in both bytes and hexadecimal form.
- Byte Representation:
b'|'
is the ASCII character|
(vertical bar) as a byte. The vertical bar has a decimal ASCII value of124
. - Hex Representation:
7c
is the hexadecimal form of124
(7 * 16^1 + 12 * 16^0 = 124
). This again shows the conversion from an ASCII character to its hexadecimal representation.
- Byte Representation:
b'B'
represents the ASCII characterB
as a byte, which has a decimal value of66
in the ASCII table. - Hex Representation:
42
is the hexadecimal notation for66
(4 * 16^1 + 2 * 16^0 = 66
). This illustrates the byte and hex representation for the uppercase letterB
.
- Byte Representation:
b'\xed'
specifies a byte with the hexadecimal value ofed
. The\x
prefix is used to denote hex values in byte literals. - Hex Representation:
ed
corresponds directly to the hexadecimal valueed
, which is237
in decimal (14 * 16^1 + 13 * 16^0 = 237
).
Each example shows how a 1-byte value can be represented as a byte literal in Python and its corresponding hexadecimal value. The hexadecimal representation is a more human-readable way to express binary data, especially in cryptographic contexts where keys and other binary data are commonly represented in hex.