SLENSER

Untitled

Dec 5th, 2023
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. import math
  2. import string
  3. import secrets
  4.  
  5.  
  6. def choose_alphabet(alphabet_types):
  7.     alphabets = {
  8.         'latin_uppercase': string.ascii_uppercase,
  9.         'latin_lowercase': string.ascii_lowercase,
  10.         'russian_uppercase': 'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ',
  11.         'russian_lowercase': 'абвгдежзийклмнопрстуфхцчшщъыьэюя',
  12.         'symbols': string.punctuation,
  13.         'digits': string.digits,
  14.     }
  15.  
  16.     chosen_alphabet = ''
  17.     for alphabet_type in alphabet_types:
  18.         alphabet = alphabets.get(alphabet_type)
  19.         if alphabet:
  20.             chosen_alphabet += alphabet
  21.  
  22.     return chosen_alphabet, len(chosen_alphabet)
  23.  
  24.  
  25. def generate_password(length, alphabet):
  26.     password = ''.join(secrets.choice(alphabet) for _ in range(length))
  27.     return password
  28.  
  29.  
  30. P = 10e-7
  31. V = 10
  32. T = 30240
  33.  
  34. S1 = math.ceil(V * T / P)  # нижняя граница
  35. alphabet, A = choose_alphabet(["latin_uppercase", "symbols"])
  36. L = 0
  37.  
  38. while not (S1 <= A ** L):
  39.     L += 1
  40.  
  41. print("S* =", S1)
  42. print("A =", A)
  43. print("L =", L)
  44. print("password:", generate_password(L, alphabet))
  45.  
Advertisement
Add Comment
Please, Sign In to add comment