

import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812





def a():





	'''simple docstring'''
	print('Making key files...'	)
	make_key_files('rsa'			, 1024	)
	print('Key files generation successful.'	)





def a(lowercase__	):





	'''simple docstring'''
	print('Generating prime p...'	)
	snake_case_      		= rabinMiller.generate_large_prime(lowercase__	)
	print('Generating prime q...'	)
	snake_case_      		= rabinMiller.generate_large_prime(lowercase__	)
	snake_case_      		= p * q

	print('Generating e that is relatively prime to (p - 1) * (q - 1)...'	)
	while True:
		snake_case_      		= random.randrange(2 ** (key_size - 1)			, 2 ** (key_size)	)
		if cryptoMath.gcd(lowercase__			, (p - 1) * (q - 1)	) == 1:
			break

	print('Calculating d that is mod inverse of e...'	)
	snake_case_      		= cryptoMath.find_mod_inverse(lowercase__			, (p - 1) * (q - 1)	)

	snake_case_      		= (n, e)
	snake_case_      		= (n, d)
	return (public_key, private_key)





def a(lowercase__			, lowercase__	):





	'''simple docstring'''
	if os.path.exists(f"""{name}_pubkey.txt"""	) or os.path.exists(f"""{name}_privkey.txt"""	):
		print('\nWARNING:'	)
		print(
		    f"""\"{name}_pubkey.txt\" or \"{name}_privkey.txt\" already exists. \n"""
		    'Use a different name or delete these files and re-run this program.'	)
		sys.exit()

	snake_case_		,       snake_case_      		= generate_key(lowercase__	)
	print(f"""\nWriting public key to file {name}_pubkey.txt..."""	)
	with open(f"""{name}_pubkey.txt"""			, 'w'	) as out_file:
		out_file.write(f"""{key_size},{public_key[0]},{public_key[1]}"""	)

	print(f"""Writing private key to file {name}_privkey.txt..."""	)
	with open(f"""{name}_privkey.txt"""			, 'w'	) as out_file:
		out_file.write(f"""{key_size},{private_key[0]},{private_key[1]}"""	)


if __name__ == "__main__":
		main()



import unittest

import numpy as np
import torch

from diffusers import ScoreSdeVePipeline, ScoreSdeVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()


class SCREAMING_SNAKE_CASE  (		unittest.TestCase							):






			"""simple docstring"""




			@property
			def 			__lowerCAmelCase (    self							):

				"""simple docstring"""


				torch.manual_seed(0							)
				snake_case_      		= UNetaDModel(
				    block_out_channels=(32, 64) ,				layers_per_block=2 ,				sample_size=32 ,				in_channels=3 ,				out_channels=3 ,				down_block_types=('DownBlock2D', 'AttnDownBlock2D') ,				up_block_types=('AttnUpBlock2D', 'UpBlock2D') ,				)
				return model







			def 			__lowerCAmelCase (    self							):

				"""simple docstring"""


				snake_case_      		= self.dummy_uncond_unet
				snake_case_      		= ScoreSdeVeScheduler()

				snake_case_      		= ScoreSdeVePipeline(unet=__UpperCamelCase ,				scheduler=__UpperCamelCase							)
				sde_ve.to(__UpperCamelCase							)
				sde_ve.set_progress_bar_config(disable=__UpperCamelCase							)

				snake_case_      		= torch.manual_seed(0							)
				snake_case_      		= sde_ve(num_inference_steps=2 ,				output_type='numpy' ,				generator=__UpperCamelCase							).images

				snake_case_      		= torch.manual_seed(0							)
				snake_case_      		= sde_ve(num_inference_steps=2 ,				output_type='numpy' ,				generator=__UpperCamelCase ,				return_dict=__UpperCamelCase							)[
				    0
				]

				snake_case_      		= image[0, -3:, -3:, -1]
				snake_case_      		= image_from_tuple[0, -3:, -3:, -1]

				assert image.shape == (1, 32, 32, 3)
				snake_case_      		= np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]							)

				assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2
				assert np.abs(image_from_tuple_slice.flatten() - expected_slice							).max() < 1E-2







@slow
@require_torch
class SCREAMING_SNAKE_CASE  (		unittest.TestCase							):






			"""simple docstring"""




			def 			__lowerCAmelCase (    self							):

				"""simple docstring"""


				snake_case_      		= 'google/ncsnpp-church-256'
				snake_case_      		= UNetaDModel.from_pretrained(__UpperCamelCase							)

				snake_case_      		= ScoreSdeVeScheduler.from_pretrained(__UpperCamelCase							)

				snake_case_      		= ScoreSdeVePipeline(unet=__UpperCamelCase ,				scheduler=__UpperCamelCase							)
				sde_ve.to(__UpperCamelCase							)
				sde_ve.set_progress_bar_config(disable=__UpperCamelCase							)

				snake_case_      		= torch.manual_seed(0							)
				snake_case_      		= sde_ve(num_inference_steps=10 ,				output_type='numpy' ,				generator=__UpperCamelCase							).images

				snake_case_      		= image[0, -3:, -3:, -1]

				assert image.shape == (1, 2_56, 2_56, 3)

				snake_case_      		= np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]							)

				assert np.abs(image_slice.flatten() - expected_slice							).max() < 1E-2
