Ver código fonte

Initial commit

Dennis Rodewyk 5 anos atrás
commit
e6e5584f89
4 arquivos alterados com 98 adições e 0 exclusões
  1. 2 0
      .gitignore
  2. 20 0
      Makefile
  3. 22 0
      README.md
  4. 54 0
      app.go

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+.idea/
+passphrase-entropy

+ 20 - 0
Makefile

@@ -0,0 +1,20 @@
+INSTDIR?=/usr/local
+BINDIR?=$(INSTDIR)/bin
+GO?=go
+
+GOSRC!=find . -name '*.go'
+
+passphrase-entropy: $(GOSRC)
+	$(GO) build \
+		-o $@
+
+# Exists in GNUMake but not in NetBSD make and others.
+RM?=rm -f
+
+clean:
+	$(RM) passphrase-entropy
+
+install: passphrase-entropy
+	mkdir -p $(BINDIR)
+	install -m755 $< $(BINDIR)/$<
+

+ 22 - 0
README.md

@@ -0,0 +1,22 @@
+### Passphrase Entropy Calculator
+
+#### Build
+
+```
+make
+make install
+```
+
+#### Usage
+```
+passphrase-entropy a passphrase
+```
+
+#### Output
+```
+Evaluated string: a passphrase
+
+Used character sets: Lowercase, Common Special Characters
+
+Passphrase entropy: 71.4503557246425
+```

+ 54 - 0
app.go

@@ -0,0 +1,54 @@
+package main
+
+import (
+	"fmt"
+	"math"
+	"os"
+	"strings"
+)
+
+func contains(arr [3]string, str string) bool {
+	for _, a := range arr {
+		if a == str {
+			return true
+		}
+	}
+	return false
+}
+
+func main() {
+
+	var charsets map[string]string
+	var usedCharsets[] string
+	var possibleSymbols int = 0
+
+	if len(os.Args) == 1 {
+			fmt.Println("Usage:\n\tpassphrase-entropy passphrase\n\nNo passphrase given.")
+			os.Exit(0)
+	}
+
+	passphrase := strings.Join(os.Args[1:]," ")
+	passphraseLength := len(passphrase)
+
+	fmt.Println("\nEvaluated string:", passphrase)
+
+	charsets = make(map[string]string)
+	charsets["Numbers"] = "0123456789"
+	charsets["Lowercase"] = "abcdefghijklmnopqrstuvwxyz"
+	charsets["Uppercase"] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+	charsets["Common Special Characters"] = " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~‚"
+	charsets["Extended ASCII"] = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
+
+	for key, value := range charsets {
+		if strings.ContainsAny(passphrase, value) {
+			possibleSymbols += len(value)
+			usedCharsets = append(usedCharsets, key)
+		}
+	}
+
+	entropy := math.Log2(math.Pow(float64(possibleSymbols), float64(passphraseLength)))
+
+	fmt.Println("\nNumber of characters:", passphraseLength)
+	fmt.Println("\nUsed character sets:", strings.Join(usedCharsets, ", "))
+	fmt.Println("\nPassphrase entropy:", entropy)
+}