benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 254ae628-419f-53ab-93de-2031fc42676f
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import numpy as np
import base64
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
def task_func(num, from_base, to_base, private_key, alphabet):
"""
Converts a number from one base to another, signs it with a private RSA key,
and encodes the signed number in base64 using a custom alphabet.
Parameters:
- num (str): The number to be converted, represented as a string.
- from_base (int): The base of the number to be converted.
- to_base (int): The base to convert the number to.
- private_key (Any): The private RSA key for signing. The type hint is `Any` due to the dynamic nature of key objects.
- alphabet (str): A string representing the custom alphabet for base64 encoding.
Returns:
- str: The base64-encoded signed number.
Example:
>>> from cryptography.hazmat.backends import default_backend
>>> from cryptography.hazmat.primitives.asymmetric import rsa
>>> private_key = rsa.generate_private_key( \
public_exponent=65537, \
key_size=2048, \
backend=default_backend() \
)
>>> alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"
>>> encoded = task_func('A1', 16, 8, private_key, alphabet)
>>> print(encoded)
XMBRyV7pyHXbaojpPuA3iv42nL5AVNukWQjfG48OnojFHtklqZuEgYoOwUZiQAj/dUxXANzzHuKjGRoPcuN5An7J7Gs8pEfEnOmnJfJgGLeiBgAXUeBl5aUTDoMIzBt5exSJWnNC1h5KXp+dDCpB4Hz3qIqdHyqHGNBExXZcEDOW6bEvF+rQOoQpxUJ6Xh3M/46i0g+vSDVyxLxurZpfVNQjEkrV8IlQXXdHoy4ciUC4YrwM0FrdM1BIWdzrhL9k6NfJeI96rabT8xHLrnZDH57mJqWBhpywVFtB7BEnqND70T0fpauFKtuaiA3jc+IydFC+lvodTWe3LiqI2WBsQw==
>>> isinstance(encoded, str)
True
Requirements:
- numpy
- cryptography.hazmat.primitives.hashes
- cryptography.hazmat.primitives.asymmetric.padding
- base64
Note:
- The function assumes that the provided number can be successfully converted from the specified source base to the target base.
- The RSA private key must be generated and provided to sign the converted number.
- The custom alphabet for base64 encoding allows for flexibility in encoding schemes.
"""
instruct prompt
Converts a number from one base to another, signs it with a private RSA key, and encodes the signed number in base64 using a custom alphabet.
Note that: The function assumes that the provided number can be successfully converted from the specified source base to the target base. The RSA private key must be generated and provided to sign the converted number. The custom alphabet for base64 encoding allows for flexibility in encoding schemes.
The function should output with:
str: The base64-encoded signed number.
You should write self-contained code starting with:
Code
import numpy as np
import base64
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
def task_func(num, from_base, to_base, private_key, alphabet):
code prompt
Code
import numpy as np
import base64
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
def task_func(num, from_base, to_base, private_key, alphabet):
entry point
task_func
libs
- base64
- numpy
- cryptography
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
initial import