allow unicode in complexity calculations
@@ -4450,13 +4450,12 @@ class CRYPT(Validator):
# entropy calculator for IS_STRONG
#
-lowerset = frozenset(u"abcdefghijklmnopqrstuvwxyz")
-upperset = frozenset(u"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
-numberset = frozenset(u"0123456789")
-sym1set = frozenset(u"!@#$%^&*()")
-sym2set = frozenset(u"~`-_=+[]{}\\|;:'\",.<>?/")
-otherset = frozenset(u"0123456789abcdefghijklmnopqrstuvwxyz") # anything else
-
+lowerset = frozenset(b"abcdefghijklmnopqrstuvwxyz")
+upperset = frozenset(b"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+numberset = frozenset(b"0123456789")
+sym1set = frozenset(b"!@#$%^&*() ")
+sym2set = frozenset(b"~`-_=+[]{}\\|;:'\",.<>?/")
+otherset = frozenset(b''.join(chr(x).encode() for x in range(256)))
def calc_entropy(string):
""" calculates a simple entropy for a given string """
@@ -4464,14 +4463,15 @@ def calc_entropy(string):
other = set()
seen = set()
lastset = None
- string = to_unicode(string)
+ string = to_bytes(string)
for c in string:
# classify this character
- inset = otherset
- for cset in (lowerset, upperset, numberset, sym1set, sym2set):
+ inset = None
+ for cset in (lowerset, upperset, numberset, sym1set, sym2set, otherset):
if c in cset:
inset = cset
break
+ assert inset is not None
# calculate effect of character on alphabet size
if inset not in seen:
seen.add(inset)
