def produceMasterProfileFAR(text, user): all_keyHoldTime = [] all_interkeyTime = [] filename = 'processedData/text{0}/user{1}.json'.format(text, user) with open(filename, 'r') as f: data = [json.loads(line) for line in f] outliers = getPositionOfOutliers(text, user) data = [timings for i, timings in enumerate(data) if not i in outliers] for i, timings in enumerate(data): ikt = calculateInterkeyTime(timings['keyPressData'], timings['keyReleaseData']) kht = calculateKeyHoldTime(timings['keyPressData'], timings['keyReleaseData']) if len(ikt) > len(kht): del ikt[-1] elif len(kht) > len(ikt): del kht[-1] all_interkeyTime.append(ikt) all_keyHoldTime.append(kht) master_interkeyTime = [ statistics.mean(time) for time in zip(*all_interkeyTime) ] master_keyHoldTime = [ statistics.mean(time) for time in zip(*all_keyHoldTime) ] return (master_interkeyTime, master_keyHoldTime, all_interkeyTime, all_keyHoldTime)
def profilePlot(): all_keyHoldTime = [] all_interkeyTime = [] for user in range(1, 2): for text in range(1, 2): filename = 'processedData/text{0}/user{1}.json'.format(text, user) with open(filename, 'r') as f: data = [json.loads(line) for line in f] outliers = getPositionOfOutliers(text, user) data = [ timings for i, timings in enumerate(data) if not i in outliers ] for i, timings in enumerate(data): ikt = calculateInterkeyTime(timings['keyPressData'], timings['keyReleaseData']) kht = calculateKeyHoldTime(timings['keyPressData'], timings['keyReleaseData']) if len(ikt) > len(kht): del ikt[-1] elif len(kht) > len(ikt): del kht[-1] all_interkeyTime.append(ikt) all_keyHoldTime.append(kht) fig = int('{}{}'.format(user, text)) plt.figure(fig) plt.plot([i / 10000 for i in kht], [i / 10000 for i in ikt]) plt.xlabel('Key Hold Time (*10^4)(microseconds)') plt.ylabel('Interkey Time (*10^4)(microseconds)') plt.savefig('user{}-text{}.png'.format(user, text))
def authenticateFRR(user, text, comparator): master_ikt, master_kht, c, d = produceMasterProfileFRR(text, user) count = 0 allUserCount = 0 filename = 'processedData/text{0}/user{1}.json'.format(text, user) with open(filename, 'r') as f: data = [json.loads(line) for line in f] outliers = getPositionOfOutliers(text, user) data = [timings for i, timings in enumerate(data) if not i in outliers] for timings in data[5:]: ikt = calculateInterkeyTime(timings['keyPressData'], timings['keyReleaseData']) kht = calculateKeyHoldTime(timings['keyPressData'], timings['keyReleaseData']) if len(ikt) > len(kht): del ikt[-1] elif len(kht) > len(ikt): del kht[-1] euclideanDistance = [ ((x1 - x2)**2 + (y1 - y2)**2)**(1 / 2) for x1, y1, x2, y2 in zip(master_ikt, master_kht, ikt, kht) ] dissimilarity = sum(euclideanDistance) authenticationValue = 1 if dissimilarity <= comparator else 0 user = '******' if authenticationValue == 1 else 'Imposter' if user == 'Imposter': count += 1 allUserCount += 1 return ((count / allUserCount) * 100)
def authenticate(): dp, dr = extractTimings(dataProcess(pressdata), dataProcess(releasedata)) lt = calculateLatencyTime(dp, dr) ikt = calculateInterkeyTime(dp, dr) # master_lt = [] # master_ikt = [] master_lt, master_ikt = produceMasterProfile() euclideanDistance = [ ((x1 - x2)**2 + (y1 - y2)**2)**(1 / 2) for x1, y1, x2, y2 in zip(master_lt, master_ikt, lt, ikt) ] dissimilarity = sum(euclideanDistance) comparator = generateComparator() authenticationValue = 1 if dissimilarity <= comparator else 0 # print(authenticationValue) user = '******' if authenticationValue == 1 else 'Imposter' print(user)
def plotOfBoxplots(): filename = 'processedData/text{0}/user{1}.json'.format(3, 1) with open(filename, 'r') as f: data = [json.loads(line) for line in f] all_ikt = [[ i / 10000 for i in calculateInterkeyTime(timings['keyPressData'], timings['keyReleaseData']) ] for timings in data] ikt = [list(lst) for lst in zip(*all_ikt)] plt.figure() plt.boxplot(ikt, vert=0) my_yticks = [ 's-t', 't-u', 'u-d', 'd-e', 'e-n', 'n-t', 't-space', 'space-h', 'h-e', 'e-l', 'l-l', 'l-o', 'o-space', 'space-w', 'w-o', 'o-r', 'r-l', 'l-d' ] plt.yticks(list(range(1, 19)), my_yticks) plt.xlabel('Range of interkey values (*10^4)(microseconds)') plt.ylabel('Box plots') plt.show()
def produceMasterProfile(): with open('data.json', 'r') as f: data = json.load(f) for timings in data: lt = calculateLatencyTime(timings['keyPressData'], timings['keyReleaseData']) ikt = calculateInterkeyTime(timings['keyPressData'], timings['keyReleaseData']) all_latencyTime.append(lt) all_interkeyTime.append(ikt) master_latencyTime = [ statistics.mean(time) for time in zip(*all_latencyTime) ] master_interkeyTime = [ statistics.mean(time) for time in zip(*all_interkeyTime) ] # print(master_latencyTime) # print(master_interkeyTime) plt.figure(1) plt.plot(master_latencyTime, master_interkeyTime) # plt.show() return (master_latencyTime, master_interkeyTime)
def produceMasterProfileFRR(text, user): all_keyHoldTime = [] all_interkeyTime = [] filename = 'processedData/text{0}/user{1}.json'.format(text, user) with open(filename, 'r') as f: data = [json.loads(line) for line in f] outliers = getPositionOfOutliers(text, user) data = [timings for i, timings in enumerate(data) if not i in outliers] # here only 5 records have been used because after removing outliers around 20 records are only left # per user; so only 5 for master profile generation and remaining for authentication for timings in data[:5]: ikt = calculateInterkeyTime(timings['keyPressData'], timings['keyReleaseData']) kht = calculateKeyHoldTime(timings['keyPressData'], timings['keyReleaseData']) if len(ikt) > len(kht): del ikt[-1] elif len(kht) > len(ikt): del kht[-1] all_interkeyTime.append(ikt) all_keyHoldTime.append(kht) master_interkeyTime = [ statistics.mean(time) for time in zip(*all_interkeyTime) ] master_keyHoldTime = [ statistics.mean(time) for time in zip(*all_keyHoldTime) ] return (master_interkeyTime, master_keyHoldTime, all_interkeyTime, all_keyHoldTime)