keyize

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2020 License: MIT Imports: 5 Imported by: 0

README

keyize

Go Keyize keystroke dynamics library

PkgGoDev

The keyize package provides types Recording and Dynamics.

Recording supports the manual addition of RecordingEvents, and can also parse recordings in the KeyizeV1 format. (eg. those created with KeyizeBiometry/web-recorder)

Dynamics support a number of operations, and should cover most processing use-cases.

Install

go get github.com/KeyizeBiometry/keyize

Import Recording and Get Dynamics

rec, err := keyize.ImportKeyizeV1("dH357uH582de1110ue1389dl2345ul2853dl3604ul4299do4458uo4729d 5583u 5815dw5942uw6196do6770uo7254dr7507ur7907dl8904ul9411dd10384ud10637")

// rec.Events will contain a list of parsed recording events

if err != nil {...}

// Convert to Dynamics

dyn := rec.Dynamics()
// Now an []DynamicsProperty has been extracted from the Recording and a Dynamics has been created

Compare Dynamics

// Proportion match (experimental)

manhattanDist := dyn1.ProportionMatch(dyn2)
// => 0.96

// Manhattan Distance

manhattanDist := dyn1.ManhattanDist(dyn2, nil)

// Euclidean Distance

euclideanDist := dyn1.EuclideanDist(dyn2, nil)

// Average property difference (scaled)

avgScaledDiff := dyn1.AvgScaledPropDiff(dyn2, nil)

Note

This library is not yet complete. Some features are planned or being considered:

  • Export Dynamics encoded as []byte using Protocol Buffers
  • Export Recording encoded as KeyizeV1
  • Refine and further test Dynamics ProportionMatch method
  • Significantly improve test coverage

Documentation

Overview

Package keyize provides abstractions to be used for the representation and computation of keystroke-related data. Keyize supports a wide array of keystroke recording and keystroke dynamics processing activities.

Index

Constants

View Source
const AvgScaledPropDiffOther float64 = 16.85
View Source
const AvgScaledPropDiffSame float64 = 7.69

Scaling for use in ProportionMatch. Provides a range for mapping result from AvgScaledPropDiff.

Original detected average range is: 7.69, 16.85

Variables

This section is empty.

Functions

This section is empty.

Types

type Dynamics

type Dynamics struct {
	// contains filtered or unexported fields
}

Dynamics represents a group of dynamics properties

func AvgDynamics

func AvgDynamics(d []*Dynamics) *Dynamics

AvgDynamics returns a pointer to a new Dynamics which is the average of all Dynamics contained from d.

func NewDynamics

func NewDynamics() *Dynamics

func (*Dynamics) AddProperty

func (d *Dynamics) AddProperty(p *DynamicsProperty)

AddProperty adds DynamicsProperty p to the internal map in Dynamics d.

func (*Dynamics) AddPropertyByName

func (d *Dynamics) AddPropertyByName(name string, value float64) error

AddPropertyByName adds DynamicsProperty p to the internal map in Dynamics d from name.

func (*Dynamics) AvgScaledPropDiff

func (d *Dynamics) AvgScaledPropDiff(a *Dynamics, propertyKindScaleMap DynamicsPropertyKindScaleMap) float64

AvgScaledPropDiff returns the average distance between scaled values of properties shared between Dynamics d and a.

func (*Dynamics) EuclideanDist

func (d *Dynamics) EuclideanDist(a *Dynamics, propertyKindScaleMap DynamicsPropertyKindScaleMap) (dist float64)

EuclideanDist uses the Euclidean distance metric to find distance between Dynamics d and a.

It uses propertyKindScaleMap for scaling. nil may be passed for propertyKindScaleMap and the optimized defaults will be used.

func (*Dynamics) ManhattanDist

func (d *Dynamics) ManhattanDist(a *Dynamics, propertyKindScaleMap DynamicsPropertyKindScaleMap) (dist float64)

ManhattanDist uses the Manhattan distance metric to find distance between Dynamics d and a.

It uses propertyKindScaleMap for scaling. nil may be passed for propertyKindScaleMap and the optimized defaults will be used.

func (*Dynamics) Properties

func (d *Dynamics) Properties() map[string]*DynamicsProperty

Properties returns the internally managed set of properties.

func (*Dynamics) ProportionMatch

func (d *Dynamics) ProportionMatch(a *Dynamics) float64

ProportionMatch returns a usable match proportion between Dynamics d and a, on a scale of 0.0 to 1.0.

func (*Dynamics) ProportionSharedProperties

func (d *Dynamics) ProportionSharedProperties(a *Dynamics, method SharedPropertiesMethod) float64

ProportionSharedProperties returns the proportion of properties shared between Dynamics d and a with respect to SharedPropertiesMethod method.

func (*Dynamics) RemoveProperty

func (d *Dynamics) RemoveProperty(p *DynamicsProperty)

RemoveProperty removes DynamicsProperty p from the internal map in Dynamics d.

func (*Dynamics) SharedProperties

func (d *Dynamics) SharedProperties(a *Dynamics, method SharedPropertiesMethod) (shared int, total int)

SharedProperties returns the count of properties shared between Dynamics d and a as well as the count of total properties considered with respect to SharedPropertiesMethod method.

type DynamicsProperty

type DynamicsProperty struct {
	Kind  DynamicsPropertyKind
	KeyA  rune
	KeyB  rune
	Value float64
}

DynamicsProperty is a keystroke dynamics property, often synthesized from a Recording.

func ParseDynamicsPropertyName

func ParseDynamicsPropertyName(n string) (*DynamicsProperty, error)

func (*DynamicsProperty) Name

func (d *DynamicsProperty) Name() string

Name provides the name for the property (this can be used as a key by a Dynamics)

type DynamicsPropertyKind

type DynamicsPropertyKind int
const (
	Dwell DynamicsPropertyKind = iota
	DownDown
	UpDown
)

type DynamicsPropertyKindScaleMap

type DynamicsPropertyKindScaleMap map[DynamicsPropertyKind]float64

DynamicsPropertyKindScaleMap is a map of DynamicsPropertyKind to scaling values. It is used when calculating distance between multiple Dynamics.

If a key is missing, it may be replaced with the default, optimized value if present. Using the optimized default scale values by passing nil to distance methods for the propertyKindScaleMap argument is recommended.

type RawEventKind

type RawEventKind int
const (
	KeyDown RawEventKind = iota
	KeyUp
)

type Recording

type Recording struct {
	Events []*RecordingEvent
}

Recording represents a user's raw typing recording

func ImportKeyizeV1

func ImportKeyizeV1(d string) (*Recording, error)

ImportKeyizeV1 imports a keystroke recording of the Keyize V1 format. These recordings may be generated from users by a corresponding recording library.

func (*Recording) Dynamics

func (r *Recording) Dynamics() *Dynamics

Dynamics converts the raw data from Recording r to Dynamics d by extracting and averaging timings.

func (*Recording) Text

func (r *Recording) Text() string

Text returns the (approximate) text typed in Recording r.

type RecordingEvent

type RecordingEvent struct {
	At      int
	Kind    RawEventKind
	Subject rune
}

RecordingEvent is a specific event which took place during a recording

type SharedPropertiesMethod

type SharedPropertiesMethod int
const (
	// Consider properties from Dynamics d and a
	Both SharedPropertiesMethod = iota

	// Consider properties from only Dynamics d
	Left

	// Consider properties from only Dynamics a
	Right
)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL