| 1 | package maclogin |
| 2 | |
| 3 | type loginKey struct { |
| 4 | code int |
| 5 | shift bool |
| 6 | } |
| 7 | |
| 8 | |
| 9 | func passwordKeys(password string) ([]loginKey, bool) { |
| 10 | rows := []struct { |
| 11 | characters string |
| 12 | code int |
| 13 | }{ |
| 14 | {"aA", 0}, {"sS", 1}, {"dD", 2}, {"fF", 3}, {"hH", 4}, {"gG", 5}, {"zZ", 6}, {"xX", 7}, {"cC", 8}, {"vV", 9}, |
| 15 | {"bB", 11}, {"qQ", 12}, {"wW", 13}, {"eE", 14}, {"rR", 15}, {"yY", 16}, {"tT", 17}, |
| 16 | {"1!", 18}, {"2@", 19}, {"3#", 20}, {"4$", 21}, {"6^", 22}, {"5%", 23}, {"=+", 24}, {"9(", 25}, {"7&", 26}, {"-_", 27}, {"8*", 28}, {"0)", 29}, |
| 17 | {"]}", 30}, {"oO", 31}, {"uU", 32}, {"[{", 33}, {"iI", 34}, {"pP", 35}, {"lL", 37}, {"jJ", 38}, {"'\"", 39}, {"kK", 40}, {";:", 41}, {"\\|", 42}, {",<", 43}, {"/?", 44}, {"nN", 45}, {"mM", 46}, {".>", 47}, {"`~", 50}, {" ", 49}, |
| 18 | } |
| 19 | if len(password) < 8 || len(password) > 256 { |
| 20 | return nil, false |
| 21 | } |
| 22 | result := make([]loginKey, 0, len(password)) |
| 23 | for _, ch := range password { |
| 24 | found := false |
| 25 | for _, row := range rows { |
| 26 | for index, candidate := range row.characters { |
| 27 | if ch == candidate { |
| 28 | result = append(result, loginKey{row.code, index == 1}) |
| 29 | found = true |
| 30 | break |
| 31 | } |
| 32 | } |
| 33 | if found { |
| 34 | break |
| 35 | } |
| 36 | } |
| 37 | if !found { |
| 38 | return nil, false |
| 39 | } |
| 40 | } |
| 41 | return result, true |
| 42 | } |