<commit_before>""" util.py

utility functions for debutils.pgp
"""
import binascii
import math


def bytes_to_int(b):
    return int(binascii.hexlify(b), 16)


def int_to_bytes(i, minlen=1):
    plen = max(int(math.ceil(i.bit_length() / 8.0)) * 2, (minlen * 2))
    hexstr = '{0:0{1}x}'.format(i, plen).encode()
    return binascii.unhexlify(hexstr)<commit_msg>added a method to util to compute the modular multiplicative inverse of two numbers (borrowed the code from the cryptography 0.4 codebase; this can go away when cryptography 0.4 actually comes out)<commit_after>""" util.py

utility functions for debutils.pgp
"""
import binascii
import math

def bytes_to_int(b):
    return int(binascii.hexlify(b), 16)


def int_to_bytes(i, minlen=1):
    plen = max(int(math.ceil(i.bit_length() / 8.0)) * 2, (minlen * 2))
    hexstr = '{0:0{1}x}'.format(i, plen).encode()
    return binascii.unhexlify(hexstr)


# borrowed from the development version of cryptography
# https://github.com/pyca/cryptography/blob/master/cryptography/hazmat/primitives/asymmetric/rsa.py
def modinv(e, m):
    """
    Modular Multiplicative Inverse. Returns x such that: (x * e) % m == 1
    """
    x1, y1, x2, y2 = 1, 0, 0, 1
    a, b = e, m
    while b > 0:
        q, r = divmod(a, b)
        xn, yn = x1 - q * x2, y1 - q * y2
        a, b, x1, y1, x2, y2 = b, r, x2, y2, xn, yn
    return x1 % m
{'fraction_non_alphanumeric': 0.1431686046511628, 'fraction_numerical': 0.032703488372093026, 'mean_word_length': 3.3714285714285714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 1, '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': '6383722', 'n_tokens_mistral': 570, 'n_tokens_neox': 531, 'n_words': 152}