The problem
An InBody result contains a QR code, which raises a reasonable question: what is in it? This project examines the encoded binary data, maps positions to measurements, and turns those findings into Python tools.
The approach: The Python packages separate binary decoding, field discovery, API access, and command-line use. Mutation-based experiments help identify what each field represents.
Reported project measurements: Sub-millisecond payload decoding; 100% reconstruction fidelity across 30+ body composition biometrics; automated differential mutation testing suite.
How it works
The Differential Mutation Oracle is a test harness that mutates fixed-width byte slices one at a time and watches the output, which is how it finds each biomarker's boundaries and scale factor.
A byte-slice parser converts the ASCII place-value fields into calibrated floating-point measurements.
A normalizer decodes percent-encoded delimiters, and a deriver computes indicators such as Appendicular Skeletal Muscle Mass and Skeletal Muscle Index.
How the pieces connect
flowchart TD
A[InBody Result Sheet QR Code] --> B[Raw IBData Query String]
B --> C[Percent-Encoding Normalizer]
C --> D[Multi-Segment Delimiter Lexer]
D --> E1[Segment 4: Body Composition Matrix]
D --> E2[Segment 5: Visceral Fat & BMR Matrix]
E1 & E2 --> F[Positional Place-Value Deserializer]
F --> G[Derived Biomarker Engine: ASM, SMI, ECW/TBW]
G --> H[Structured JSON / Dataframe Export]
Implementation notes
Positional Place-Value Deserializer (inbody-decoder/src/decoder.py)
# Fixed-width positional place-value matrix deserializer
def decode_digits(raw_slice: str, scale_factor: float = 0.1, precision: int = 2, meas_blob: str = "") -> float:
"""Fixed-width positional matrix deserializer for place-value byte windows in meas_blob."""
clean_digits = raw_slice.strip()
accumulated_value = sum(
(ord(char) - ord('0')) * (10 ** idx)
for idx, char in enumerate(reversed(clean_digits))
)
return round(accumulated_value * scale_factor, precision)
Differential Mutation Testing Oracle (inbody-cli/mapping.py)
# Programmatic field discovery via differential mutation
def probe_byte_slice(payload: str, start: int, end: int, delta: int = 1) -> str:
"""Injects controlled integer perturbations to isolate biometric offsets."""
chars = list(payload)
val = int("".join(chars[start:end])) + delta
chars[start:end] = f"{val:0{end - start}d}"
return "".join(chars)
Tradeoffs and lessons
- URL percent-encoding turned literal
!delimiters into%21, which shifted the byte slices and produced a $10\times$ error in Leg Lean Mass until the delimiters were normalized. - The core decoder uses only the Python standard library, so it can be embedded in constrained IoT and mobile environments.