Advertisement
rosien

KS_2022_C_New_Password

May 22nd, 2022
1,273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. def char_type(character):
  2.     if ord('0') <= character <= ord('9'):
  3.         return 'number'
  4.     if ord('A') <= character <= ord('Z'):
  5.         return 'uppercase'
  6.     if ord('a') <= character<= ord('z'):
  7.         return 'lowercase'
  8.     if character in {64, 42, 35, 38}:
  9.         return 'special_case'
  10.  
  11. def rule_to_char(rule):
  12.     if rule == 'number':
  13.         return '0'
  14.     if rule == 'uppercase':
  15.         return 'A'
  16.     if rule == 'lowercase':
  17.         return 'a'
  18.     if rule == 'special_case':
  19.         return '#'
  20.  
  21. rules = {'number', 'uppercase', 'lowercase', 'special_case'}
  22.  
  23. def new_password(L, old_password):
  24.     requirement = set()
  25.     for i in old_password:
  26.         requirement.add(char_type(ord(i)))
  27.     requirement_to_fill = rules - requirement
  28.     if  requirement_to_fill != '':
  29.         for to_fill in requirement_to_fill:
  30.             old_password += rule_to_char(to_fill)
  31.     if len(old_password)<7:
  32.         old_password += 'a' * (7-len(old_password))
  33.     return old_password
  34.  
  35. testcase = int(input())
  36.  
  37. for test in range(testcase):
  38.     L = int(input())
  39.     old_password = input()
  40.     answer = new_password(L, old_password)
  41.     print(f'Case # {test +1}: {answer}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement