Advertisement
Programmin-in-Python

Number of Unique Passwords after Repeated Permutations

Dec 22nd, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. def perm(str1):
  2.     L1 = list(str1)
  3.     str2 = ""
  4.     res = []
  5.  
  6.     for i in range(len(L1)):
  7.         for j in range(len(L1)):
  8.             if (i+j)%2 == 0:
  9.                 temp = L1[i]
  10.                 L1[i] = L1[j]
  11.                 L1[j] = temp
  12.  
  13.                 for k in L1:
  14.                     str2 += k
  15.                 else:
  16.                     if str2 not in res:
  17.                         res.append(str2)
  18.                         str2 = ""
  19.                     else:
  20.                         str2=""
  21.  
  22.     res.remove(str1)
  23.  
  24.     return res
  25.  
  26. def no_unique_pass(arr):
  27.     no_uni_pass = 1
  28.     L1_res = []
  29.  
  30.     for i in arr:
  31.         res = perm(i)
  32.         j = 0
  33.  
  34.         while j < len(arr):
  35.             if bool(res.count(arr[j])):
  36.                 del arr[j]
  37.  
  38.             j += 1
  39.  
  40.     else:
  41.         no_uni_pass += (len(arr) - 1)
  42.  
  43.     return no_uni_pass
  44.  
  45. def main():
  46.     L1 = []
  47.  
  48.     n = int(input("Enter the Number of Users : "))
  49.     print("\nEnter the Users' password one-by-one...")
  50.  
  51.     for i in range(n):
  52.         password = input("Enter the Password : ")
  53.         L1.append(password)
  54.  
  55.     unique_pass = no_unique_pass(L1)
  56.  
  57.     print("Number of Unique Passwords : ", unique_pass)
  58.  
  59. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement