benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a6564624-8ab4-5ad6-962b-8cd41e788a8e

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import binascii
import hashlib


def task_func(input_string, verify_hash=None):
    """
    Compute the SHA256 hash of a given input string and return its hexadecimal representation.
    Optionally, verify the computed hash against a provided hash.

    Parameters:
    - input_string (str): The string to be hashed.
    - verify_hash (str, optional): A hexadecimal string to be compared with the computed hash.

    Returns:
    - str: A hexadecimal string representing the SHA256 hash of the input string.
    - bool: True if verify_hash is provided and matches the computed hash, otherwise None.

    Raises:
    - TypeError: If the input is not a string or verify_hash is not a string or None.

    Requirements:
    - hashlib
    - binascii

    Example:
    >>> task_func("Hello, World!")
    'dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f'
    >>> task_func("Hello, World!", "dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f")
    True
    """

instruct prompt

Compute the SHA256 hash of a given input string and return its hexadecimal representation. Optionally, verify the computed hash against a provided hash.
The function should raise the exception for: TypeError: If the input is not a string or verify_hash is not a string or None.
The function should output with:
    str: A hexadecimal string representing the SHA256 hash of the input string.
    bool: True if verify_hash is provided and matches the computed hash, otherwise None.
You should write self-contained code starting with:

Code

import binascii
import hashlib
def task_func(input_string, verify_hash=None):

code prompt

Code

import binascii
import hashlib
def task_func(input_string, verify_hash=None):

entry point

task_func

libs

  • hashlib
  • binascii

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import