Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def attackList(accessList, m, n):
- #Create a function to return the dates converted to seconds
- def tosecond(s):
- #Choose 170101000000 as the point of reference
- month = {'01':0, '02':2678400, '03':5097600, '04':7776000, '05':10368000, '06':13046400, '07': 15638400, '08':18316800, '09': 20995200, '10':23587200, '11':26265600, '12':28857600}
- result = (int(s[:2])-17)*31536000
- result += month[s[2:4]]
- result += int(s[4:6])*24*60**2
- result += int(s[6:8])*60**2
- result += int(s[8:10])*60
- result += int(s[10:12])
- return result
- #A function calculating if the two dates is within m mins
- def iswithin(s1,s2):
- difference = abs(s1 - s2)
- if difference <= m*60:
- return True
- else:
- return False
- #A list of distinct usernames
- name = []
- for e in accessList:
- if e[13:] not in name:
- name.append(e[13:])
- if n == 1:
- return sorted(name)
- hack = []
- for e in name:
- accessTime = []
- count = 1
- for j in accessList:
- if j[13:] == e:
- accessTime.append(tosecond(j))
- sorted(accessTime) #A sorted list of access time of the e user
- for i in range(len(accessTime) - 1):
- if iswithin(accessTime[i],accessTime[i+1]):
- count +=1
- if count == n and iswithin(accessTime[i+2-n],accessTime[i+1]):
- hack.append(e)
- break
- else:
- count = 1
- return sorted(hack)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement