Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
578 views

Python - User-Friendly Password System

Fresco Play hands on
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
578 views

Python - User-Friendly Password System

Fresco Play hands on
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#!

/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'authEvents' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts 2D_STRING_ARRAY events as parameter.
#

# def authEvents(events):
# # Write your code here

def authEvents(events):
print(events)
import string

h = list(string.ascii_letters)+ [str(d) for d in range(10)] # + [""]


# Write your code here
ans = []
for i in range(len(events)):
def f(x):
z = ord("%s" %x)
return z

def hash_val(lst, ln):


count =1
w=[]
for ij in lst:
t= f(ij) * (131** (ln-count))
w.append(t)
count= count+1
return sum(w) % (10**9+7)

if events[i][0] == 'setPassword':
lst= list(events[i][1])
ln = len(lst)

res =[]
res.append(hash_val(lst, ln))

for k in h:
lst_add= list(events[i][1])
lst_add.append(k)
ln_add = len(lst_add)
res.append(hash_val(lst_add, ln_add))

print(res)
if events[i][0] == "authorize":
if int(events[i][1]) in res:
ans.append(1)
else:
ans.append(0)

return ans

if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

events_rows = int(input().strip())
events_columns = int(input().strip())

events = []

for _ in range(events_rows):
events.append(input().rstrip().split())

result = authEvents(events)

fptr.write('\n'.join(map(str, result)))
fptr.write('\n')

fptr.close()

You might also like