


import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

lowercase__				     =		3






def __UpperCamelCase   (			__lowerCamelCase		: Dict				)      ->     int:







     '''simple docstring'''






     print("Generating primitive root of p"				)
     while True:
          _a						=		random.randrange(3      ,  lowerCamelCase_				)
          if pow(lowerCamelCase_      ,  2      ,  lowerCamelCase_				) == 1:
               continue
          if pow(lowerCamelCase_      ,  lowerCamelCase_      ,  lowerCamelCase_				) == 1:
               continue
          return g






def __UpperCamelCase   (			__lowerCamelCase		: Union[str, Any]				)      ->     tuple[tuple[int, int, int, int], tuple[int, int]]:







     '''simple docstring'''






     print("Generating prime p..."				)
     _a						=		rabin_miller.generate_large_prime(lowerCamelCase_				)  # select large prime number.
     _a						=		primitive_root(lowerCamelCase_				)  # one primitive root on modulo p.
     _a						=		random.randrange(3      ,  lowerCamelCase_				)  # private_key -> have to be greater than 2 for safety.
     _a						=		cryptomath.find_mod_inverse(pow(lowerCamelCase_      ,  lowerCamelCase_      ,  lowerCamelCase_				)      ,  lowerCamelCase_				)

     _a						=		(key_size, e_a, e_a, p)
     _a						=		(key_size, d)

     return public_key, private_key






def __UpperCamelCase   (			__lowerCamelCase		: int      ,  __lowerCamelCase		: Union[str, Any]				)      ->     None:







     '''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()

     _a						=		generate_key(lowerCamelCase_				)
     print(F"\nWriting public key to file {name}_pubkey.txt..."				)
     with open(F"{name}_pubkey.txt"      ,  "w"				) as fo:
          fo.write(F"{public_key[0]},{public_key[1]},{public_key[2]},{public_key[3]}"				)

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






def __UpperCamelCase   (			)      ->     None:







     '''simple docstring'''






     print("Making key files..."				)
     make_key_files("elgamal"      ,  2048				)
     print("Key files generation successful"				)


if __name__ == "__main__":
   main()





'''simple docstring'''

from __future__ import annotations

import requests






def __UpperCamelCase   (			__lowerCamelCase		: str				)      ->     dict:







     '''simple docstring'''






     _a						=		F"https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty"
     return requests.get(__lowerCamelCase				).json()






def __UpperCamelCase   (			__lowerCamelCase		: int = 10				)      ->     list[dict]:







     '''simple docstring'''






     _a						=		"https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
     _a						=		requests.get(__lowerCamelCase				).json()[:max_stories]
     return [get_hackernews_story(__lowerCamelCase				) for story_id in story_ids]






def __UpperCamelCase   (			__lowerCamelCase		: int = 10				)      ->     str:







     '''simple docstring'''






     _a						=		hackernews_top_stories(__lowerCamelCase				)
     return "\n".join("* [{title}]({url})".format(**__lowerCamelCase				) for story in stories				)


if __name__ == "__main__":
   print(hackernews_top_stories_as_markdown())

