<commit_before>import nacl.secret
import nacl.utils
import six
from nacl.exceptions import CryptoError
from polymorphic.models import PolymorphicModel

from django.conf import settings
from django.contrib.sites.models import Site
from django.core.mail.message import EmailMultiAlternatives
from django.db import models
from django.template import Context, Template
from django.utils import timezone
from django.utils.crypto import get_random_string
# from django.utils.encoding import force_bytes
from django.utils.html import strip_tags

from callisto.delivery.hashers import get_hasher, identify_hasher

# change this to the value previously used
ORIGINAL_KEY_ITERATIONS = 100


def _encrypt_report(salt, stretched_key, report_text):
    """Encrypts a report using the given secret key & salt. Requires a stretched key with a length of 32 bytes.
    The encryption uses PyNacl & Salsa20 stream cipher.

    Args:
      salt (str): cryptographic salt
      stretched_key (str): secret key after being stretched
      report_text (str): full report as a string

    Returns:
      bytes: the encrypted bytes of the report

    """
    box = nacl.secret.SecretBox(stretched_key)
    message = report_text.encode('utf-8')
    nonce = nacl.utils.random(nacl.secret.SecretBox.NONCE_SIZE)
    return box.encrypt(message, nonce)


def _decrypt_report(salt, stretched_key, encrypted):
    """Decrypts an encrypted report.
<commit_msg>remove extraneous commented-out import<commit_after>import nacl.secret
import nacl.utils
import six
from nacl.exceptions import CryptoError
from polymorphic.models import PolymorphicModel

from django.conf import settings
from django.contrib.sites.models import Site
from django.core.mail.message import EmailMultiAlternatives
from django.db import models
from django.template import Context, Template
from django.utils import timezone
from django.utils.crypto import get_random_string
from django.utils.html import strip_tags

from callisto.delivery.hashers import get_hasher, identify_hasher

# change this to the value previously used
ORIGINAL_KEY_ITERATIONS = 100


def _encrypt_report(salt, stretched_key, report_text):
    """Encrypts a report using the given secret key & salt. Requires a stretched key with a length of 32 bytes.
    The encryption uses PyNacl & Salsa20 stream cipher.

    Args:
      salt (str): cryptographic salt
      stretched_key (str): secret key after being stretched
      report_text (str): full report as a string

    Returns:
      bytes: the encrypted bytes of the report

    """
    box = nacl.secret.SecretBox(stretched_key)
    message = report_text.encode('utf-8')
    nonce = nacl.utils.random(nacl.secret.SecretBox.NONCE_SIZE)
    return box.encrypt(message, nonce)


def _decrypt_report(salt, stretched_key, encrypted):
    """Decrypts an encrypted report.

{'fraction_non_alphanumeric': 0.06358177322500883, 'fraction_numerical': 0.00565171317555634, 'mean_word_length': 4.509727626459144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5419702', 'n_tokens_mistral': 833, 'n_tokens_neox': 784, 'n_words': 277}