<s> import string <EOL> class CPSecurityHelper ( object ) : <EOL> def calculate_complexity ( self , secret ) : <EOL> score = <NUM_LIT:0> <EOL> score += self . _num_chars_evaluator ( secret ) <EOL> score += self . _num_uc_evaluator ( secret ) <EOL> score += self . _num_lc_evaluator ( secret ) <EOL> score += self . _num_digits_evaluator ( secret ) <EOL> score += self . _num_punct_evaluator ( secret ) <EOL> score += self . _num_categories_evaluator ( secret ) <EOL> score -= self . _letters_only_penalty ( secret ) <EOL> score -= self . _numbers_only_penalty ( secret ) <EOL> score -= self . _letters_repeat_penalty ( secret ) <EOL> score -= self . _consecutive_uc_letters_penalty ( secret ) <EOL> score -= self . _consecutive_lc_letters_penalty ( secret ) <EOL> score -= self . _consecutive_numbers_penalty ( secret ) <EOL> score -= self . _sequential_letters_penalty ( secret ) <EOL> score -= self . _sequential_numbers_penalty ( secret ) <EOL> score -= self . _sequential_punct_penalty ( secret ) <EOL> score = min ( score , <NUM_LIT:100> ) <EOL> score = max ( score , <NUM_LIT:0> ) <EOL> status = self . _get_status ( score ) <EOL> return score , status <EOL> def _get_status ( self , score ) : <EOL> if score < <NUM_LIT> : <EOL> return '<STR_LIT>' <EOL> elif score < <NUM_LIT> : <EOL> return '<STR_LIT>' <EOL> elif score < <NUM_LIT> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return '<STR_LIT>' <EOL> def _num_chars_evaluator ( self , secret ) : <EOL> return len ( secret ) * <NUM_LIT:4> <EOL> def _num_uc_evaluator ( self , secret ) : <EOL> num_uc = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) ) : <EOL> if secret [ i ] in string . ascii_uppercase : <EOL> num_uc += <NUM_LIT:1> <EOL> return num_uc * <NUM_LIT:2> <EOL> def _num_lc_evaluator ( self , secret ) : <EOL> num_uc = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) ) : <EOL> if secret [ i ] in string . ascii_lowercase : <EOL> num_uc += <NUM_LIT:1> <EOL> return num_uc * <NUM_LIT:2> <EOL> def _num_digits_evaluator ( self , secret ) : <EOL> num_uc = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) ) : <EOL> if secret [ i ] in string . digits : <EOL> num_uc += <NUM_LIT:1> <EOL> return num_uc * <NUM_LIT:4> <EOL> def _num_punct_evaluator ( self , secret ) : <EOL> num_uc = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) ) : <EOL> if secret [ i ] in string . punctuation : <EOL> num_uc += <NUM_LIT:1> <EOL> return num_uc * <NUM_LIT:6> <EOL> def _num_categories_evaluator ( self , secret ) : <EOL> has_lc = <NUM_LIT:0> <EOL> has_uc = <NUM_LIT:0> <EOL> has_d = <NUM_LIT:0> <EOL> has_p = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) ) : <EOL> if secret [ i ] in string . punctuation : <EOL> has_p = <NUM_LIT:1> <EOL> elif secret [ i ] in string . digits : <EOL> has_d = <NUM_LIT:1> <EOL> elif secret [ i ] in string . ascii_uppercase : <EOL> has_uc = <NUM_LIT:1> <EOL> elif secret [ i ] in string . ascii_lowercase : <EOL> has_lc = <NUM_LIT:1> <EOL> return ( has_p + has_d + has_uc + has_lc ) * <NUM_LIT:2> <EOL> def _letters_only_penalty ( self , secret ) : <EOL> for i in range ( len ( secret ) ) : <EOL> if secret [ i ] in string . punctuation : <EOL> return <NUM_LIT:0> <EOL> elif secret [ i ] in string . digits : <EOL> return <NUM_LIT:0> <EOL> return len ( secret ) <EOL> def _numbers_only_penalty ( self , secret ) : <EOL> for i in range ( len ( secret ) ) : <EOL> if secret [ i ] in string . punctuation : <EOL> return <NUM_LIT:0> <EOL> elif secret [ i ] in string . ascii_lowercase : <EOL> return <NUM_LIT:0> <EOL> elif secret [ i ] in string . ascii_uppercase : <EOL> return <NUM_LIT:0> <EOL> return len ( secret ) <EOL> def _letters_repeat_penalty ( self , secret ) : <EOL> penalty = <NUM_LIT:0> <EOL> last_char = '<STR_LIT:0>' <EOL> for i in range ( len ( secret ) ) : <EOL> if ( secret [ i ] in string . ascii_lowercase or <EOL> secret [ i ] in string . ascii_uppercase ) : <EOL> if secret [ i ] . lower ( ) == last_char . lower ( ) : <EOL> penalty += <NUM_LIT:1> <EOL> last_char = secret [ i ] . lower ( ) <EOL> else : <EOL> last_char = '<STR_LIT:0>' <EOL> return penalty * <NUM_LIT:4> <EOL> def _consecutive_uc_letters_penalty ( self , secret ) : <EOL> penalty = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) - <NUM_LIT:1> ) : <EOL> if ( secret [ i ] in string . ascii_uppercase and <EOL> secret [ i + <NUM_LIT:1> ] in string . ascii_uppercase ) : <EOL> penalty += <NUM_LIT:1> <EOL> return penalty * <NUM_LIT:2> <EOL> def _consecutive_lc_letters_penalty ( self , secret ) : <EOL> penalty = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) - <NUM_LIT:1> ) : <EOL> if ( secret [ i ] in string . ascii_lowercase and <EOL> secret [ i + <NUM_LIT:1> ] in string . ascii_lowercase ) : <EOL> penalty += <NUM_LIT:1> <EOL> return penalty * <NUM_LIT:2> <EOL> def _consecutive_numbers_penalty ( self , secret ) : <EOL> penalty = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) - <NUM_LIT:1> ) : <EOL> if ( secret [ i ] in string . digits and <EOL> secret [ i + <NUM_LIT:1> ] in string . digits ) : <EOL> penalty += <NUM_LIT:1> <EOL> return penalty * <NUM_LIT:2> <EOL> def _sequential_letters_penalty ( self , secret ) : <EOL> penalty = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) - <NUM_LIT:2> ) : <EOL> if ( ( secret [ i ] in string . ascii_uppercase or <EOL> secret [ i ] in string . ascii_lowercase ) and <EOL> ( secret [ i + <NUM_LIT:1> ] in string . ascii_uppercase or <EOL> secret [ i + <NUM_LIT:1> ] in string . ascii_lowercase ) and <EOL> ( secret [ i + <NUM_LIT:2> ] in string . ascii_uppercase or <EOL> secret [ i + <NUM_LIT:2> ] in string . ascii_lowercase ) ) : <EOL> val1 = ord ( secret [ i ] . lower ( ) ) <EOL> val2 = ord ( secret [ i + <NUM_LIT:1> ] . lower ( ) ) <EOL> val3 = ord ( secret [ i + <NUM_LIT:2> ] . lower ( ) ) <EOL> if ( val2 - val1 ) == <NUM_LIT:1> : <EOL> if ( val3 - val2 ) == <NUM_LIT:1> : <EOL> penalty += <NUM_LIT:1> <EOL> return penalty * <NUM_LIT:3> <EOL> def _sequential_numbers_penalty ( self , secret ) : <EOL> penalty = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) - <NUM_LIT:2> ) : <EOL> if ( secret [ i ] in string . digits and <EOL> secret [ i + <NUM_LIT:1> ] in string . digits and <EOL> secret [ i + <NUM_LIT:2> ] in string . digits ) : <EOL> val1 = int ( secret [ i ] ) <EOL> val2 = int ( secret [ i + <NUM_LIT:1> ] ) <EOL> val3 = int ( secret [ i + <NUM_LIT:2> ] ) <EOL> if ( val2 - val1 ) == <NUM_LIT:1> : <EOL> if ( val3 - val2 ) == <NUM_LIT:1> : <EOL> penalty += <NUM_LIT:1> <EOL> return penalty * <NUM_LIT:3> <EOL> def _get_punct_index ( self , value ) : <EOL> punct = [ '<STR_LIT:!>' , '<STR_LIT:@>' , '<STR_LIT:#>' , '<STR_LIT:$>' , '<STR_LIT:%>' , '<STR_LIT>' , '<STR_LIT:&>' , '<STR_LIT:*>' , '<STR_LIT:(>' , '<STR_LIT:)>' ] <EOL> return punct . index ( value ) <EOL> def _sequential_punct_penalty ( self , secret ) : <EOL> penalty = <NUM_LIT:0> <EOL> for i in range ( len ( secret ) - <NUM_LIT:2> ) : <EOL> if ( secret [ i ] in string . punctuation and <EOL> secret [ i + <NUM_LIT:1> ] in string . punctuation and <EOL> secret [ i + <NUM_LIT:2> ] in string . punctuation ) : <EOL> val1 = self . _get_punct_index ( secret [ i ] ) <EOL> val2 = self . _get_punct_index ( secret [ i + <NUM_LIT:1> ] ) <EOL> val3 = self . _get_punct_index ( secret [ i + <NUM_LIT:2> ] ) <EOL> if ( val2 - val1 ) == <NUM_LIT:1> : <EOL> if ( val3 - val2 ) == <NUM_LIT:1> : <EOL> penalty += <NUM_LIT:1> <EOL> return penalty * <NUM_LIT:3> </s>
