<commit_before>#!/usr/local/bin/python

"""
RSA.py

@author Elliot and Erica
"""

import random
from cryptography_utilities import (block_split, decimal_to_binary,
    binary_to_decimal, gcd, extended_gcd, random_prime, left_pad,
    pad_plaintext, unpad_plaintext, random_relative_prime,
    group_exponentiation)

MODULUS_BITS = 16

def key_generation():
    """Return a tuple of (prime1, prime2, modulus, public_key, private_key).
    the size of the prime numbers is determined by the PRIME_BITS global.
    """
    prime1 = random_prime(MODULUS_BITS / 2)
    prime2 = random_prime(MODULUS_BITS / 2)
    modulus = prime1 * prime2
    totient = (prime1 - 1) * (prime2 - 1)
    public_key = random_relative_prime(totient, MODULUS_BITS / 2)
    if extended_gcd(public_key, totient)[1] < 0:
        private_key = extended_gcd(public_key, totient)[1] + totient
    else:
        private_key = extended_gcd(public_key, totient)[1]
    return modulus, public_key, private_key<commit_msg>Update the documentation of key_generation<commit_after>#!/usr/local/bin/python

"""
RSA.py

@author Elliot and Erica
"""

import random
from cryptography_utilities import (block_split, decimal_to_binary,
    binary_to_decimal, gcd, extended_gcd, random_prime, left_pad,
    pad_plaintext, unpad_plaintext, random_relative_prime,
    group_exponentiation)

MODULUS_BITS = 16

def key_generation():
    """Return a tuple of (modulus, public_key, private_key). The size of
    modulus (and associated primes) is determined by the MODULUS_BITS
    global.
    """
    prime1 = random_prime(MODULUS_BITS / 2)
    prime2 = random_prime(MODULUS_BITS / 2)
    modulus = prime1 * prime2
    totient = (prime1 - 1) * (prime2 - 1)
    public_key = random_relative_prime(totient, MODULUS_BITS / 2)
    if extended_gcd(public_key, totient)[1] < 0:
        private_key = extended_gcd(public_key, totient)[1] + totient
    else:
        private_key = extended_gcd(public_key, totient)[1]
    return modulus, public_key, private_key
{'fraction_non_alphanumeric': 0.09295352323838081, 'fraction_numerical': 0.017991004497751123, 'mean_word_length': 4.186528497409326, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3758030', 'n_tokens_mistral': 707, 'n_tokens_neox': 676, 'n_words': 164}