bytes_to_elements_with_padding

Function bytes_to_elements_with_padding 

Source
pub fn bytes_to_elements_with_padding(bytes: &[u8]) -> Vec<BaseElement>
Expand description

Converts a sequence of bytes into vector field elements with padding. This guarantees that no two sequences or bytes map to the same sequence of field elements.

Packs bytes into chunks of BINARY_CHUNK_SIZE and adds padding to the final chunk using a 1 bit followed by zeros. This ensures the original bytes can be recovered during decoding without any ambiguity.

Note that by the endianness of the conversion as well as the fact that we are packing at most 56 = 7 * 8 bits in each field element, the padding above with 1 should never overflow the field size.

§Arguments

  • bytes - Byte slice to encode

§Returns

Vector of Felt elements with the last element containing padding