Commit c5d44272 authored by Mathieu Valois's avatar Mathieu Valois
Browse files

Doc

parent d8273830
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -6,6 +6,9 @@ import Levenshtein as leven

class Robustness:
	def __init__(self, filename):
		"""
		filename is the name of the file where passwords are stored
		"""
		self.l = list()
		with open(filename) as inbuff:
			for word in inbuff:
@@ -16,6 +19,10 @@ class Robustness:
		self.algo = self.rperm

	def rperm(self):
		"""
		generator for a random permutation of the list self.l using
		Fisher-Yates algorithm
		"""
		d = len(self.l)
		for i in range(d):
			r = rand.randint(i, d-1)
@@ -23,6 +30,10 @@ class Robustness:
			yield self.l[i]

	def cost_rate(self):
		"""
		runs an excursion and return its cost rate.
		Parameters are fixed using object members (l, k, algo, distance)
		"""
		c = 0
		k = self.k
		ratio = len(self.l) / self.k
@@ -37,6 +48,9 @@ class Robustness:
		return int(c * ratio)

	def min_rperm(self, n=1):
		"""
		runs n excursions and returns the lowest cost rate found among them.
		"""
		min_c = self.cost_rate()
		for i in range(n-1):
			min_c = min(min_c, self.cost_rate())