benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 980ea946-a6d1-52ec-8a9e-26c54ec9530f

Problem

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

complete prompt

import os
import hashlib
import base64

def task_func(password, PREFIX="ME", SALT_LENGTH=16):
    """
    Generates a hashed password by concatenating a given password with a prefix and a generated salt,
    and then hashing the combined string using SHA256. The hashed result is then encoded in base64.

    Parameters:
    - password (str): The password string to hash.
    - PREFIX (str): A prefix added to the password before hashing. Defaults to "ME".
    - SALT_LENGTH (int): The byte length of the random salt to be generated. Defaults to 16.

    Returns:
    - str: The base64 encoded SHA256 hash of the password concatenated with the prefix and salt.

    Raises:
    ValueError if the SALT_LENGTH is negative

    Requirements:
    - os
    - hashlib
    - base64

    Example:
    >>> hashed_password = task_func('password123', 'ME', 16)
    >>> isinstance(hashed_password, str)
    True
    """

instruct prompt

Generates a hashed password by concatenating a given password with a prefix and a generated salt, and then hashing the combined string using SHA256. The hashed result is then encoded in base64.
The function should raise the exception for: ValueError if the SALT_LENGTH is negative
The function should output with:
    str: The base64 encoded SHA256 hash of the password concatenated with the prefix and salt.
You should write self-contained code starting with:

Code

import os
import hashlib
import base64
def task_func(password, PREFIX="ME", SALT_LENGTH=16):

code prompt

Code

import os
import hashlib
import base64
def task_func(password, PREFIX="ME", SALT_LENGTH=16):

entry point

task_func

libs

  • base64
  • hashlib
  • os

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