CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-xxhash

Python binding for xxHash library providing fast non-cryptographic hash algorithms

Overall
score

80%

Evaluation80%

1.03x

Agent success when using this tile

Overview
Eval results
Files

task.mdevals/scenario-8/

Binary Hash Digest Analyzer

Overview

Build a binary hash digest analyzer that processes data streams and extracts hash values in various byte orderings and formats. The analyzer should handle binary digest representations and provide utilities for converting between different byte order formats.

Requirements

Core Functionality

Implement a module that provides the following capabilities:

  1. Hash Computation: Compute hashes for given byte data using 64-bit hash algorithms

  2. Binary Digest Extraction: Extract hash digests as raw binary bytes

  3. Byte Order Conversion: Convert hash digest bytes between big-endian and little-endian representations

  4. Digest Comparison: Compare hash digests in their binary form to verify data integrity

Input/Output Specifications

  • Input: Byte sequences (bytes or bytearray objects)
  • Output: Binary digests as bytes, with utilities for byte order conversion

Implementation Requirements

  1. Create a function compute_digest(data: bytes) -> bytes that:

    • Accepts byte data as input
    • Returns the hash digest as raw bytes
    • Uses a 64-bit hash algorithm
  2. Create a function swap_endianness(digest: bytes) -> bytes that:

    • Accepts a binary digest
    • Returns the digest with reversed byte order
    • Handles digests of any length (4, 8, or 16 bytes)
  3. Create a function compare_digests(data: bytes, expected_little_endian_hex: str) -> bool that:

    • Computes the digest for the input data
    • Converts the digest to little-endian format
    • Compares it against the expected little-endian hex string
    • Returns True if they match, False otherwise

File Structure

Create the following files:

  • digest_analyzer.py: Main implementation module
  • test_digest_analyzer.py: Test file with test cases

Test Cases { .test-cases }

Test Case 1: Basic Hash Computation @test

Input:

data = b"hello world"
digest = compute_digest(data)

Expected Output: The digest should be 8 bytes long (64-bit hash) and returned as a bytes object.

Validation:

assert len(digest) == 8
assert isinstance(digest, bytes)

Test Case 2: Endianness Conversion @test

Input:

# Big-endian digest (example)
big_endian = b'\x01\x02\x03\x04\x05\x06\x07\x08'
little_endian = swap_endianness(big_endian)

Expected Output:

little_endian == b'\x08\x07\x06\x05\x04\x03\x02\x01'

Test Case 3: Digest Verification @test

Input:

data = b"test data"
# Compare against a known little-endian hex string
result = compare_digests(data, "c394c5c28df8b07e")

Expected Output:

# Should return True when the computed digest
# (converted to little-endian) matches the expected value
assert isinstance(result, bool)

Dependencies { .dependencies }

xxhash { .dependency }

Provides fast non-cryptographic hash functions with support for binary digest output.

Constraints

  • Use only standard library modules for byte manipulation (no external libraries except xxhash)
  • Handle byte sequences correctly without making assumptions about encoding
  • Ensure proper byte order handling for cross-platform compatibility

Success Criteria

  • All test cases pass
  • Functions correctly handle binary digest representations
  • Byte order conversions work correctly for different digest sizes
  • Code properly demonstrates understanding of endianness in hash outputs

Install with Tessl CLI

npx tessl i tessl/pypi-xxhash

tile.json