~seirdy/moac

c7e44a97bfc2392ebc5256b8cddc73c89d7ac4b3 — Rohan Kumar 2 years ago 6ff0419
Fix: remove ineffective code (from mutesting)

Mutation testing revealed some code to have no effect; remove it.
Further testing showed that some code intended to improve performance
(e.g. exiting loops early) did absolutely nothing.

One of these changes made the computation of guesses-per-second in
Givens.Populate() mirror everything else that used setBottleneck; since
everything else had been moved to its own function, do the same for
guesses-per-second.
4 files changed, 16 insertions(+), 14 deletions(-)

M charsets/charsets.go
M entropy/entropy.go
M givens.go
M pwgen/pwgen.go
M charsets/charsets.go => charsets/charsets.go +2 -2
@@ 82,7 82,7 @@ func (cs *CharsetCollection) AddDefault(newCharsets ...DefaultCharset) {
}

func (cs *CharsetCollection) addSingle(c CustomCharset) {
	for i := 0; i < len(*cs) && len(c) > 0; i++ {
	for i := 0; i < len(*cs); i++ {
		minimizeRedundancyInLatter(&(*cs)[i], &c)
	}



@@ 99,7 99,7 @@ func (cs *CharsetCollection) Combined() CustomCharset {
		ccBuilder.WriteString(c.String())
	}

	return CustomCharset([]rune(ccBuilder.String()))
	return []rune(ccBuilder.String())
}

// ParseCharsets creates a CharsetCollection from string identifiers.

M entropy/entropy.go => entropy/entropy.go +1 -1
@@ 54,7 54,7 @@ func findCharsetsUsed(password string) charsets.CharsetCollection {

	for _, charset := range charsets.DefaultCharsets {
		if strings.ContainsAny(filteredPassword, charset.String()) {
			charsetsUsed = append(charsetsUsed, charset)
			charsetsUsed.AddDefault(charset)
			filterFromString(&filteredPassword, charset.Runes())
		}
	}

M givens.go => givens.go +10 -8
@@ 93,6 93,15 @@ func (givens *Givens) calculatePower() {
	setBottleneck(&givens.Power, powerFromComputationSpeed, powerFromEnergy)
}

func (givens *Givens) calculateGPS() {
	var (
		bremermannGPS = Bremermann * givens.Mass
		powerGPS      = givens.Power / givens.EnergyPerGuess
	)

	setBottleneck(&givens.GuessesPerSecond, bremermannGPS, powerGPS)
}

func (givens *Givens) calculateEnergy() {
	var (
		energyFromMass  = givens.Mass * C * C


@@ 138,14 147,7 @@ func (givens *Givens) Populate() error {

	givens.calculatePower()

	var bremermannGPS float64

	if givens.GuessesPerSecond == 0 && givens.Mass != 0 {
		bremermannGPS = Bremermann * givens.Mass
	}

	powerGPS := givens.Power / givens.EnergyPerGuess
	setBottleneck(&givens.GuessesPerSecond, bremermannGPS, powerGPS)
	givens.calculateGPS()

	givens.calculateEnergy()


M pwgen/pwgen.go => pwgen/pwgen.go +3 -3
@@ 144,7 144,8 @@ func buildFixedLengthPw(

	for specialI := 0; currentLength < pwLength; currentLength++ {
		if i := indexOf(specialIndexes, currentLength); i >= 0 {
			addRuneToEnd(pwBuilder, cs[i].Runes()) // one of each charset @ a special index
			// one of each charset @ a special index
			addRuneToEnd(pwBuilder, cs[i].Runes())
			specialI++

			continue


@@ 158,8 159,7 @@ func buildFixedLengthPw(

func randomlyInsertRunesTillStrong(
	maxLen int, pwRunes *[]rune, entropyWanted float64, combinedCharset []rune) {
	for (maxLen == 0 || len(*pwRunes) < maxLen) &&
		entropyWanted > entropy.Entropy(string(*pwRunes)) {
	for (len(*pwRunes) < maxLen) && entropyWanted > entropy.Entropy(string(*pwRunes)) {
		addRuneAtRandLoc(pwRunes, combinedCharset)
	}
}