mirror of
https://codeberg.org/scip/valpass.git
synced 2025-12-16 20:21:00 +01:00
remove mean stuff, doesn't work properly
This commit is contained in:
16
README.md
16
README.md
@@ -87,21 +87,6 @@ Of course we do not use RLE. We measure compression
|
|||||||
using the [Flate algorithm](
|
using the [Flate algorithm](
|
||||||
https://en.m.wikipedia.org/wiki/Deflate).
|
https://en.m.wikipedia.org/wiki/Deflate).
|
||||||
|
|
||||||
### Optional: arithmetic mean value
|
|
||||||
|
|
||||||
This is simply the result of summing the all the printable ascii chars
|
|
||||||
divided by password length. The ideal value would be ~80, because most
|
|
||||||
normal letters hang out in the upper area between 32 (space) and
|
|
||||||
126(tilde). We consider a password ok, if its mean lies around this
|
|
||||||
area give or take 5. If the mean departs more from this value, the
|
|
||||||
characters are consistently high or low (e.g. more numbers and upper
|
|
||||||
case letters or only lower case letters). The latter, 5, can be
|
|
||||||
tweaked. The larger the number, tha laxer the result.
|
|
||||||
|
|
||||||
Please be warned, that this metric will in most cases give you bad
|
|
||||||
results on otherwise good passwords, such as diceware passwords. Only
|
|
||||||
use it if you know what you're doing.
|
|
||||||
|
|
||||||
### Optional: dictionary check
|
### Optional: dictionary check
|
||||||
|
|
||||||
You can supply a dictionary of words of your
|
You can supply a dictionary of words of your
|
||||||
@@ -149,7 +134,6 @@ type Options struct {
|
|||||||
CharDistribution float64 // minimum character distribution in percent, default 10%
|
CharDistribution float64 // minimum character distribution in percent, default 10%
|
||||||
Entropy float64 // minimum entropy value in bits/char, default 3 bits/s
|
Entropy float64 // minimum entropy value in bits/char, default 3 bits/s
|
||||||
Dictionary *Dictionary // lookup given dictionary, the caller has to provide it
|
Dictionary *Dictionary // lookup given dictionary, the caller has to provide it
|
||||||
MeanDeviation float64 // minimum arithmetic mean deviation, by default disabled, standard 5
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
45
lib.go
45
lib.go
@@ -26,7 +26,6 @@ type Options struct {
|
|||||||
CharDistribution float64 // minimum character distribution in percent, default 10%
|
CharDistribution float64 // minimum character distribution in percent, default 10%
|
||||||
Entropy float64 // minimum entropy value in bits/char, default 3 bits/s
|
Entropy float64 // minimum entropy value in bits/char, default 3 bits/s
|
||||||
Dictionary *Dictionary // lookup given dictionary, the caller has to provide it
|
Dictionary *Dictionary // lookup given dictionary, the caller has to provide it
|
||||||
MeanDeviation float64 // minimum arithmetic mean deviation, by default disabled, standard 5
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -35,18 +34,10 @@ const (
|
|||||||
MIN_ENTROPY float64 = 3.0
|
MIN_ENTROPY float64 = 3.0
|
||||||
MIN_DICT_LEN int = 5000
|
MIN_DICT_LEN int = 5000
|
||||||
MAX_CHARS int = 95 // maximum printable US ASCII chars
|
MAX_CHARS int = 95 // maximum printable US ASCII chars
|
||||||
LIMIT_MEAN_DEVIATION float64 = 20
|
|
||||||
|
|
||||||
// we start our ascii arrays at char(32), so to have max 95
|
// we start our ascii arrays at char(32), so to have max 95
|
||||||
// elements in the slice, we subtract 32 from each ascii code
|
// elements in the slice, we subtract 32 from each ascii code
|
||||||
ascii_base byte = 32
|
ascii_base byte = 32
|
||||||
|
|
||||||
// arithmetic mean limits: we work on chr(32) til chr(126) in
|
|
||||||
// ascii. The mean value, however, is not 63 as one would suppose,
|
|
||||||
// but 80, because most used printable ascii chars exist in the
|
|
||||||
// upper area of the space. So, we take 80 as the middle ground
|
|
||||||
// and go beyond 5 up or down
|
|
||||||
mean_base float64 = 80
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Result stores the results of all validations.
|
// Result stores the results of all validations.
|
||||||
@@ -56,7 +47,6 @@ type Result struct {
|
|||||||
Compress int // actual compression rate in percent
|
Compress int // actual compression rate in percent
|
||||||
CharDistribution float64 // actual character distribution in percent
|
CharDistribution float64 // actual character distribution in percent
|
||||||
Entropy float64 // actual entropy value in bits/chars
|
Entropy float64 // actual entropy value in bits/chars
|
||||||
Mean float64 // actual arithmetic mean, close to 127.5 is best
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates a given password. You can tune its behavior
|
// Validate validates a given password. You can tune its behavior
|
||||||
@@ -73,7 +63,6 @@ func Validate(passphrase string, opts ...Options) (Result, error) {
|
|||||||
CharDistribution: MIN_DIST,
|
CharDistribution: MIN_DIST,
|
||||||
Entropy: MIN_ENTROPY,
|
Entropy: MIN_ENTROPY,
|
||||||
Dictionary: nil,
|
Dictionary: nil,
|
||||||
MeanDeviation: 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts) == 1 {
|
if len(opts) == 1 {
|
||||||
@@ -133,16 +122,6 @@ func Validate(passphrase string, opts ...Options) (Result, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.MeanDeviation > 0 {
|
|
||||||
mean := getArithmeticMean(passphrase)
|
|
||||||
|
|
||||||
if mean > (mean_base+options.MeanDeviation) || mean < (mean_base-options.MeanDeviation) {
|
|
||||||
result.Ok = false
|
|
||||||
}
|
|
||||||
|
|
||||||
result.Mean = mean
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,27 +242,3 @@ func getDictMatch(passphrase string, dict *Dictionary) (bool, error) {
|
|||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Return the arithmetic mean value:
|
|
||||||
|
|
||||||
This is simply the result of summing the all the bytes (bits if the
|
|
||||||
|
|
||||||
-b option is specified) in the file and dividing by the file
|
|
||||||
length. If the data are close to random, this should be about 127.5
|
|
||||||
(0.5 for -b option output). If the mean departs from this value, the
|
|
||||||
values are consistently high or low.
|
|
||||||
|
|
||||||
Working on US-ASCII space
|
|
||||||
*/
|
|
||||||
func getArithmeticMean(passphrase string) float64 {
|
|
||||||
sum := 0.0
|
|
||||||
count := 0.0
|
|
||||||
|
|
||||||
for _, char := range []byte(passphrase) {
|
|
||||||
sum += float64(char)
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
|
|
||||||
return sum / count
|
|
||||||
}
|
|
||||||
|
|||||||
63
lib_test.go
63
lib_test.go
@@ -171,59 +171,6 @@ var pass_dict_bad = []string{
|
|||||||
`effected`, `ministry`,
|
`effected`, `ministry`,
|
||||||
}
|
}
|
||||||
|
|
||||||
var pass_mean_bad = []string{
|
|
||||||
`UT6RTLTNAK3JN2UVWJGXSLHKT4P3ECXJ`,
|
|
||||||
`L4HENABMJR0UZBFSFV0GPSXWZ4HEMOHO`,
|
|
||||||
`YTYPHSGR8XHP4C85T3YZFF4TG2OLMQVF`,
|
|
||||||
`TWAGHNVLMYR5RW67RNKUO8K3SPYAJID2`,
|
|
||||||
`MU0OCIE9ZUYBFLMSKWKCLTSWKZ6GBTLM`,
|
|
||||||
`GHBSLIVXCJCVUNTJBSPHXZUSE906QGZH`,
|
|
||||||
`PZWQMRNG8LDRTY9GVELRALXCO181O8AK`,
|
|
||||||
`KZYKWCUZWDG4OSREEKCKOA58JQMRUUBZ`,
|
|
||||||
`CKZWG3H6A2TJKJDPEFX2CESMPYTA7WBF`,
|
|
||||||
`RT8HGYUBUNUJMF0SLWKW8JISCRSG6L6M`,
|
|
||||||
`368WCV4PGAWE1MWZJWZU8JPEQILMEBHV`,
|
|
||||||
`W6HVUTBNAGJN4ABMWEKK5OHTIXUYTPDG`,
|
|
||||||
`GZXQAEWMNSKJDYVQRPYIQXJTPIDHMF9T`,
|
|
||||||
`AWTJNUFOTML7GC2OC04K74F30AO9A2VJ`,
|
|
||||||
`MTHJUGOHCTYNWICVVNEMETRYA2L2QHBE`,
|
|
||||||
`XHTUQVYNSBPTH8TWCRMMV6BILHV6KYOP`,
|
|
||||||
`MTNAROLNNZZBARVNKGGVLL8VR682GQUP`,
|
|
||||||
`3VDYD0CJGFQ1UQKTRQOUQ5FZ4PROITVQ`,
|
|
||||||
`JWOFUTKGTVG035HUFTTWHGLECAX5IYMX`,
|
|
||||||
`DVVMB6XXZPALLFMEF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||||
`XILAMTWXXGAHHMEUPNXBP5HQEGKCFH8X`,
|
|
||||||
`OGJ7A3RNOCSGPPUXSPOING6AYUNZ8OSR`,
|
|
||||||
`LB1XL9YWUXX6Q7GJBDI0BISHG7V1PAXY`,
|
|
||||||
`YRUJYIOYDNYBUBQK0YY02WA45YNGTKMS`,
|
|
||||||
`UTPTMOILT9WI3O2ZPPASMHQYCJPO2HTT`,
|
|
||||||
`J6NXVXG5FN9CTWYEYQBLFVZSSALFDJEF`,
|
|
||||||
`CQC84VGBZMJ65I8XLRF2PBMK5X86BVMC`,
|
|
||||||
}
|
|
||||||
|
|
||||||
var pass_dictsub_bad = []string{
|
var pass_dictsub_bad = []string{
|
||||||
`regational`, `iminalizat`, `rconductiv`, `substantia`,
|
`regational`, `iminalizat`, `rconductiv`, `substantia`,
|
||||||
`oritativen`, `trocardiog`, `communicat`, `aracterist`,
|
`oritativen`, `trocardiog`, `communicat`, `aracterist`,
|
||||||
@@ -272,10 +219,6 @@ var opts_invaliddict = valpass.Options{
|
|||||||
Dictionary: &valpass.Dictionary{Words: []string{"eins", "zwei", "drei"}},
|
Dictionary: &valpass.Dictionary{Words: []string{"eins", "zwei", "drei"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
var opts_mean = valpass.Options{
|
|
||||||
MeanDeviation: 15, // very lax in order to succeed!
|
|
||||||
}
|
|
||||||
|
|
||||||
var tests = []Test{
|
var tests = []Test{
|
||||||
{
|
{
|
||||||
name: "checkgood",
|
name: "checkgood",
|
||||||
@@ -295,12 +238,6 @@ var tests = []Test{
|
|||||||
opts: opts_dictsub,
|
opts: opts_dictsub,
|
||||||
passwords: Passwordlist{pass_dictsub_bad},
|
passwords: Passwordlist{pass_dictsub_bad},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "checkgood-mean",
|
|
||||||
want: true,
|
|
||||||
opts: opts_mean,
|
|
||||||
passwords: Passwordlist{pass_random_good},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "checkbad",
|
name: "checkbad",
|
||||||
want: false,
|
want: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user