<commit_before>from cryptography.hazmat.primitives import serialization as crypto_serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.backends import default_backend as crypto_default_backend


def public_private_key():
    # https://stackoverflow.com/a/39126754/43839

    key = rsa.generate_private_key(
        backend=crypto_default_backend(),
        public_exponent=65537,
        key_size=2048
    )

    public = key.public_key().public_bytes(
        crypto_serialization.Encoding.OpenSSH,
        crypto_serialization.PublicFormat.OpenSSH
    )

    private = key.private_bytes(
        crypto_serialization.Encoding.PEM,
        crypto_serialization.PrivateFormat.PKCS8,
        crypto_serialization.NoEncryption())

    return public.decode(), private.decode()<commit_msg>Refactor crypto.py slightly<commit_after>from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.backends import default_backend

# https://stackoverflow.com/a/39126754/43839
# https://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa/


def make_private_key():
    return rsa.generate_private_key(
        backend=default_backend(),
        public_exponent=65537,
        key_size=2048)


def public_key_string(private_key):
    return private_key.public_key().public_bytes(
        serialization.Encoding.OpenSSH,
        serialization.PublicFormat.OpenSSH
    ).decode()


def private_key_string(private_key):
    return private_key.private_bytes(
        serialization.Encoding.PEM,
        serialization.PrivateFormat.PKCS8,
        serialization.NoEncryption()).decode()


def public_private_key():
    private_key = make_private_key()
    public = public_key_string(private_key)
    private = private_key_string(private_key)
    return public, private
{'fraction_non_alphanumeric': 0.08297872340425531, 'fraction_numerical': 0.02446808510638298, 'mean_word_length': 4.167582417582418, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3789764', 'n_tokens_mistral': 598, 'n_tokens_neox': 553, 'n_words': 83}