Last active
December 5, 2025 22:50
-
-
Save atoponce/c72a9dd858cace002fa115f36cfe9dca to your computer and use it in GitHub Desktop.
Generates secure passwords with at least 72 bits symmetric security using patterns on the keyboard from different English layouts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use strict"; | |
| const COLEMAK = { | |
| // top row | |
| "`": ["1", "!"], get "~"() { return this["`"]; }, | |
| "1": ["`", "~", "2", "@", "q", "Q"], get "!"() { return this["1"]; }, | |
| "2": ["1", "!", "3", "#", "w", "W"], get "@"() { return this["2"]; }, | |
| "3": ["2", "@", "4", "$", "f", "F"], get "#"() { return this["3"]; }, | |
| "4": ["3", "#", "5", "%", "p", "P"], get "$"() { return this["4"]; }, | |
| "5": ["4", "$", "6", "^", "g", "G"], get "%"() { return this["5"]; }, | |
| "6": ["5", "%", "7", "&", "j", "J"], get "^"() { return this["6"]; }, | |
| "7": ["6", "^", "8", "*", "l", "L"], get "&"() { return this["7"]; }, | |
| "8": ["7", "&", "9", "(", "u", "U"], get "*"() { return this["8"]; }, | |
| "9": ["8", "*", "0", ")", "y", "Y"], get "("() { return this["9"]; }, | |
| "0": ["9", "(", "[", "{", ";", ":"], get ")"() { return this["0"]; }, | |
| "-": ["0", ")", "=", "+", "[", "{"], get "_"() { return this["-"]; }, | |
| "=": ["-", "_", "]", "}"], get "+"() { return this["="]; }, | |
| // second row | |
| "q": ["1", "!", "w", "W", "a", "A"], get "Q"() { return this["q"]; }, | |
| "w": ["q", "Q", "f", "F", "2", "@", "r", "R"], get "W"() { return this["w"]; }, | |
| "f": ["w", "W", "p", "P", "3", "#", "s", "S"], get "F"() { return this["f"]; }, | |
| "p": ["f", "F", "g", "G", "4", "$", "t", "T"], get "P"() { return this["p"]; }, | |
| "g": ["p", "P", "j", "J", "5", "%", "d", "D"], get "G"() { return this["g"]; }, | |
| "j": ["g", "G", "l", "L", "6", "^", "h", "H"], get "J"() { return this["j"]; }, | |
| "l": ["j", "J", "u", "U", "7", "&", "n", "N"], get "L"() { return this["l"]; }, | |
| "u": ["l", "L", "y", "Y", "8", "*", "e", "E"], get "U"() { return this["u"]; }, | |
| "y": ["u", "U", ";", ";", "9", "(", "i", "I"], get "Y"() { return this["y"]; }, | |
| ";": ["y", "Y", "[", "[", "0", ")", "o", "O"], get ":"() { return this[";"]; }, | |
| "[": [";", ":", "]", "]", "[", "{", "'", '"'], get "{"() { return this["["]; }, | |
| "]": ["[", "{", "\\", "|", "=", "+", ], get "}"() { return this["]"]; }, | |
| "\\": ["]", "}"], get "|"() { return this["\\"]; }, | |
| // third row | |
| "a": ["q", "Q", "r", "R", "z", "Z"], get "A"() { return this["a"]; }, | |
| "r": ["a", "A", "s", "S", "w", "W", "x", "X"], get "R"() { return this["r"]; }, | |
| "s": ["r", "R", "t", "T", "f", "F", "c", "C"], get "S"() { return this["s"]; }, | |
| "t": ["s", "S", "d", "D", "p", "P", "v", "V"], get "T"() { return this["t"]; }, | |
| "d": ["t", "T", "h", "H", "g", "G", "b", "B"], get "D"() { return this["d"]; }, | |
| "h": ["d", "D", "n", "N", "j", "J", "k", "K"], get "H"() { return this["h"]; }, | |
| "n": ["h", "H", "e", "E", "l", "L", "m", "M"], get "N"() { return this["n"]; }, | |
| "e": ["n", "N", "i", "I", "u", "U", ",", "<"], get "E"() { return this["e"]; }, | |
| "i": ["e", "E", "o", "O", "y", "Y", ".", ">"], get "I"() { return this["i"]; }, | |
| "o": ["i", "I", "'", '"', ";", ":", "/", "?"], get "O"() { return this["o"]; }, | |
| "'": ["o", "O", "[", "{"], get '"'() { return this["'"]; }, | |
| // fourth row | |
| "z": ["a", "A", "x", "X"], get "Z"() { return this["z"]; }, | |
| "x": ["z", "Z", "c", "C", "r", "R"], get "X"() { return this["x"]; }, | |
| "c": ["x", "X", "v", "V", "s", "S"], get "C"() { return this["c"]; }, | |
| "v": ["c", "C", "b", "B", "t", "T"], get "V"() { return this["v"]; }, | |
| "b": ["v", "V", "k", "K", "d", "D"], get "B"() { return this["b"]; }, | |
| "k": ["b", "B", "m", "M", "h", "H"], get "K"() { return this["k"]; }, | |
| "m": ["k", "K", ",", "<", "n", "N"], get "M"() { return this["m"]; }, | |
| ",": ["m", "M", ".", ">", "e", "E"], get "<"() { return this[","]; }, | |
| ".": [",", "<", "/", "?", "i", "I"], get ">"() { return this["."]; }, | |
| "/": [".", ">", "o", "O"], get "?"() { return this["/"]; } | |
| }; | |
| const DVORAK = { | |
| // top row | |
| "`": ["1", "!"], get "~"() { return this["`"]; }, | |
| "1": ["`", "~", "2", "@", "'", '"'], get "!"() { return this["1"]; }, | |
| "2": ["1", "!", "3", "#", ",", "<"], get "@"() { return this["2"]; }, | |
| "3": ["2", "@", "4", "$", ".", ">"], get "#"() { return this["3"]; }, | |
| "4": ["3", "#", "5", "%", "p", "P"], get "$"() { return this["4"]; }, | |
| "5": ["4", "$", "6", "^", "y", "Y"], get "%"() { return this["5"]; }, | |
| "6": ["5", "%", "7", "&", "f", "F"], get "^"() { return this["6"]; }, | |
| "7": ["6", "^", "8", "*", "g", "G"], get "&"() { return this["7"]; }, | |
| "8": ["7", "&", "9", "(", "c", "C"], get "*"() { return this["8"]; }, | |
| "9": ["8", "*", "0", ")", "r", "R"], get "("() { return this["9"]; }, | |
| "0": ["9", "(", "[", "{", "l", "L"], get ")"() { return this["0"]; }, | |
| "[": ["0", ")", "]", "}", "/", "?"], get "{"() { return this["["]; }, | |
| "]": ["[", "{", "=", "+"], get "}"() { return this["]"]; }, | |
| // second row | |
| "'": ["1", "!", ",", "<", "a", "A"], get '"'() { return this["'"]; }, | |
| ",": ["'", '"', ".", ">", "2", "@", "o", "O"], get "<"() { return this[","]; }, | |
| ".": [",", "<", "p", "P", "3", "#", "e", "E"], get ">"() { return this["."]; }, | |
| "p": [".", ">", "y", "Y", "4", "$", "u", "U"], get "P"() { return this["p"]; }, | |
| "y": ["p", "P", "f", "F", "5", "%", "i", "I"], get "Y"() { return this["y"]; }, | |
| "f": ["y", "Y", "g", "G", "6", "^", "d", "D"], get "F"() { return this["f"]; }, | |
| "g": ["f", "F", "c", "C", "7", "&", "h", "H"], get "G"() { return this["g"]; }, | |
| "c": ["g", "G", "r", "R", "8", "*", "t", "T"], get "C"() { return this["c"]; }, | |
| "r": ["c", "C", "l", "L", "9", "(", "n", "N"], get "R"() { return this["r"]; }, | |
| "l": ["r", "R", "/", "?", "0", ")", "s", "S"], get "L"() { return this["l"]; }, | |
| "/": ["l", "L", "=", "+", "[", "{", "-", "_"], get "?"() { return this["/"]; }, | |
| "=": ["/", "?", "\\", "|", "]", "}"], get "+"() { return this["="]; }, | |
| "\\": ["=", "+", ], get "|"() { return this["\\"]; }, | |
| // third row | |
| "a": ["'", '"', "o", "O", ";", ":"], get "A"() { return this["a"]; }, | |
| "o": ["a", "A", "e", "E", ",", "<", "q", "Q"], get "O"() { return this["o"]; }, | |
| "e": ["o", "O", "u", "U", ".", ">", "j", "J"], get "E"() { return this["e"]; }, | |
| "u": ["e", "E", "i", "I", "p", "P", "k", "K"], get "U"() { return this["u"]; }, | |
| "i": ["u", "U", "d", "D", "y", "Y", "x", "X"], get "I"() { return this["i"]; }, | |
| "d": ["i", "I", "h", "H", "f", "F", "b", "B"], get "D"() { return this["d"]; }, | |
| "h": ["d", "D", "t", "T", "g", "G", "m", "M"], get "H"() { return this["h"]; }, | |
| "t": ["h", "H", "n", "N", "c", "C", "w", "W"], get "T"() { return this["t"]; }, | |
| "n": ["t", "T", "s", "S", "r", "R", "v", "V"], get "N"() { return this["n"]; }, | |
| "s": ["n", "N", "-", "_", "l", "L", "z", "Z"], get "S"() { return this["s"]; }, | |
| "-": ["s", "S", "/", "?"], get "_"() { return this["-"]; }, | |
| // fourth row | |
| ";": ["q", "Q", "a", "A"], get ":"() { return this[";"]; }, | |
| "q": [";", ":", "j", "J", "o", "O"], get "Q"() { return this["q"]; }, | |
| "j": ["q", "Q", "k", "K", "e", "E"], get "J"() { return this["j"]; }, | |
| "k": ["j", "J", "x", "X", "u", "U"], get "K"() { return this["k"]; }, | |
| "x": ["k", "K", "b", "B", "i", "I"], get "X"() { return this["x"]; }, | |
| "b": ["x", "X", "m", "M", "d", "D"], get "B"() { return this["b"]; }, | |
| "m": ["b", "B", "w", "W", "h", "H"], get "M"() { return this["m"]; }, | |
| "w": ["m", "M", "v", "V", "t", "T"], get "W"() { return this["w"]; }, | |
| "v": ["w", "W", "z", "Z", "n", "N"], get "V"() { return this["v"]; }, | |
| "z": ["v", "V", "s", "S"], get "Z"() { return this["z"]; } | |
| }; | |
| const QWERTY = { | |
| // top row | |
| "`": ["1", "!"], get "~"() { return this["`"]; }, | |
| "1": ["`", "~", "2", "@", "'", '"'], get "!"() { return this["1"]; }, | |
| "2": ["1", "!", "3", "#", ",", "<"], get "@"() { return this["2"]; }, | |
| "3": ["2", "@", "4", "$", ".", ">"], get "#"() { return this["3"]; }, | |
| "4": ["3", "#", "5", "%", "p", "P"], get "$"() { return this["4"]; }, | |
| "5": ["4", "$", "6", "^", "y", "Y"], get "%"() { return this["5"]; }, | |
| "6": ["5", "%", "7", "&", "f", "F"], get "^"() { return this["6"]; }, | |
| "7": ["6", "^", "8", "*", "g", "G"], get "&"() { return this["7"]; }, | |
| "8": ["7", "&", "9", "(", "c", "C"], get "*"() { return this["8"]; }, | |
| "9": ["8", "*", "0", ")", "r", "R"], get "("() { return this["9"]; }, | |
| "0": ["9", "(", "[", "{", "l", "L"], get ")"() { return this["0"]; }, | |
| "-": ["0", ")", "=", "+", "]", "}"], get "_"() { return this["-"]; }, | |
| "=": ["-", "_", "]", "}"], get "+"() { return this["="]; }, | |
| // second row | |
| "q": ["1", "!", "w", "W", "a", "A"], get "Q"() { return this["q"]; }, | |
| "w": ["q", "Q", "e", "E", "2", "@", "s", "S"], get "W"() { return this["w"]; }, | |
| "e": ["w", "W", "r", "R", "3", "#", "d", "D"], get "E"() { return this["e"]; }, | |
| "r": ["e", "E", "t", "T", "4", "$", "f", "F"], get "R"() { return this["r"]; }, | |
| "t": ["r", "R", "y", "Y", "5", "%", "g", "G"], get "T"() { return this["t"]; }, | |
| "y": ["t", "T", "u", "U", "6", "^", "h", "H"], get "Y"() { return this["y"]; }, | |
| "u": ["y", "Y", "i", "I", "7", "&", "j", "J"], get "U"() { return this["u"]; }, | |
| "i": ["u", "U", "o", "O", "8", "*", "k", "K"], get "I"() { return this["i"]; }, | |
| "o": ["i", "I", "p", "P", "9", "(", "l", "L"], get "O"() { return this["o"]; }, | |
| "p": ["o", "O", "[", "{", "0", ")", ";", ":"], get "P"() { return this["p"]; }, | |
| "[": ["p", "P", "]", "}", "-", "_", "'", '"'], get "{"() { return this["["]; }, | |
| "]": ["[", "{", "\\", "|", "=", "+"], get "}"() { return this["]"]; }, | |
| "\\": ["]", "}"], get "|"() { return this["\\"]; }, | |
| // third row | |
| "a": ["q", "Q", "s", "S", "z", "Z"], get "A"() { return this["a"]; }, | |
| "s": ["a", "A", "d", "D", "w", "W", "x", "X"], get "S"() { return this["s"]; }, | |
| "d": ["s", "S", "f", "F", "e", "E", "c", "C"], get "D"() { return this["d"]; }, | |
| "f": ["d", "D", "g", "G", "r", "R", "v", "V"], get "F"() { return this["f"]; }, | |
| "g": ["f", "F", "h", "H", "t", "T", "b", "B"], get "G"() { return this["g"]; }, | |
| "h": ["g", "G", "j", "J", "y", "Y", "n", "N"], get "H"() { return this["h"]; }, | |
| "j": ["h", "H", "k", "K", "u", "U", "m", "M"], get "J"() { return this["j"]; }, | |
| "k": ["j", "J", "l", "L", "i", "I", ",", "<"], get "K"() { return this["k"]; }, | |
| "l": ["k", "K", ";", ":", "o", "O", ".", ">"], get "L"() { return this["l"]; }, | |
| ";": ["l", "L", "'", '"', "p", "P", "/", "?"], get ":"() { return this[";"]; }, | |
| "'": [";", ":", "[", "{"], get '"'() { return this["'"]; }, | |
| // fourth row | |
| "z": ["a", "A", "x", "X"], get "Z"() { return this["z"]; }, | |
| "x": ["z", "Z", "c", "c", "s", "S"], get "X"() { return this["x"]; }, | |
| "c": ["x", "X", "v", "V", "d", "D"], get "C"() { return this["c"]; }, | |
| "v": ["c", "C", "b", "B", "f", "F"], get "V"() { return this["v"]; }, | |
| "b": ["v", "V", "n", "N", "g", "G"], get "B"() { return this["b"]; }, | |
| "n": ["b", "B", "m", "M", "h", "H"], get "N"() { return this["n"]; }, | |
| "m": ["n", "N", ",", "<", "j", "J"], get "M"() { return this["m"]; }, | |
| ",": ["m", "M", ".", ">", "k", "K"], get "<"() { return this[","]; }, | |
| ".": [",", "<", "/", "?", "l", "L"], get ">"() { return this["."]; }, | |
| "/": [".", ">", ";", ":"], get "?"() { return this["/"]; } | |
| }; | |
| const WORKMAN = { | |
| // top row | |
| "`": ["1", "!"], get "~"() { return this["`"]; }, | |
| "1": ["`", "~", "2", "@", "q", "Q"], get "!"() { return this["1"]; }, | |
| "2": ["1", "!", "3", "#", "d", "D"], get "@"() { return this["2"]; }, | |
| "3": ["2", "@", "4", "$", "r", "R"], get "#"() { return this["3"]; }, | |
| "4": ["3", "#", "5", "%", "w", "W"], get "$"() { return this["4"]; }, | |
| "5": ["4", "$", "6", "^", "b", "B"], get "%"() { return this["5"]; }, | |
| "6": ["5", "%", "7", "&", "j", "J"], get "^"() { return this["6"]; }, | |
| "7": ["6", "^", "8", "*", "f", "F"], get "&"() { return this["7"]; }, | |
| "8": ["7", "&", "9", "(", "u", "U"], get "*"() { return this["8"]; }, | |
| "9": ["8", "*", "0", ")", "p", "P"], get "("() { return this["9"]; }, | |
| "0": ["9", "(", "[", "{", ";", ":"], get ")"() { return this["0"]; }, | |
| "-": ["0", ")", "=", "+", "[", "{"], get "_"() { return this["-"]; }, | |
| "=": ["-", "_", "]", "}"], get "+"() { return this["="]; }, | |
| // second row | |
| "q": ["1", "!", "d", "D", "a", "A"], get "Q"() { return this["q"]; }, | |
| "d": ["q", "Q", "r", "R", "2", "@", "s", "S"], get "D"() { return this["d"]; }, | |
| "r": ["d", "D", "w", "W", "3", "#", "h", "H"], get "R"() { return this["r"]; }, | |
| "w": ["r", "R", "b", "B", "4", "$", "t", "T"], get "W"() { return this["w"]; }, | |
| "b": ["w", "W", "j", "J", "5", "%", "g", "G"], get "B"() { return this["b"]; }, | |
| "j": ["b", "B", "f", "F", "6", "^", "y", "Y"], get "J"() { return this["j"]; }, | |
| "f": ["j", "J", "u", "U", "7", "&", "n", "N"], get "F"() { return this["f"]; }, | |
| "u": ["f", "F", "p", "P", "8", "*", "e", "E"], get "U"() { return this["u"]; }, | |
| "p": ["u", "U", ";", ":", "9", "(", "o", "O"], get "P"() { return this["p"]; }, | |
| ";": ["p", "P", "[", "{", "0", ")", "i", "I"], get ":"() { return this[";"]; }, | |
| "[": [";", ":", "]", "}", "-", "_", "'", '"'], get "{"() { return this["["]; }, | |
| "]": ["[", "{", "\\", "|", "=", "+", ], get "}"() { return this["]"]; }, | |
| "\\": ["]", "}"], get "|"() { return this["\\"]; }, | |
| // third row | |
| "a": ["q", "Q", "s", "S", "z", "Z"], get "A"() { return this["a"]; }, | |
| "s": ["a", "A", "h", "H", "d", "D", "x", "X"], get "S"() { return this["s"]; }, | |
| "h": ["s", "S", "t", "T", "r", "R", "m", "M"], get "H"() { return this["h"]; }, | |
| "t": ["h", "H", "g", "G", "w", "W", "c", "C"], get "T"() { return this["t"]; }, | |
| "g": ["t", "T", "y", "Y", "b", "B", "v", "V"], get "G"() { return this["g"]; }, | |
| "y": ["g", "G", "n", "N", "j", "J", "k", "K"], get "Y"() { return this["y"]; }, | |
| "n": ["y", "Y", "e", "E", "f", "F", "l", "L"], get "N"() { return this["n"]; }, | |
| "e": ["n", "N", "o", "O", "u", "U", ",", "<"], get "E"() { return this["e"]; }, | |
| "o": ["e", "E", "i", "I", "p", "P", ".", ">"], get "O"() { return this["o"]; }, | |
| "i": ["o", "O", "'", '"', ";", ":", "/", "?"], get "I"() { return this["i"]; }, | |
| "'": ["i", "I", "[", "{"], get '"'() { return this["'"]; }, | |
| // fourth row | |
| "z": ["a", "A", "x", "X"], get "Z"() { return this["z"]; }, | |
| "x": ["z", "Z", "m", "M", "s", "S"], get "X"() { return this["x"]; }, | |
| "m": ["x", "X", "c", "C", "h", "H"], get "M"() { return this["m"]; }, | |
| "c": ["m", "M", "v", "V", "t", "T"], get "C"() { return this["c"]; }, | |
| "v": ["c", "C", "k", "K", "g", "G"], get "V"() { return this["v"]; }, | |
| "k": ["v", "V", "l", "L", "y", "Y"], get "K"() { return this["k"]; }, | |
| "l": ["k", "K", ",", "<", "n", "N"], get "L"() { return this["l"]; }, | |
| ",": ["l", "L", ".", ">", "e", "E"], get "<"() { return this[","]; }, | |
| ".": [",", "<", "/", "?", "o", "O"], get ">"() { return this["."]; }, | |
| "/": [".", ">", "i", "I"], get "?"() { return this["/"]; }, | |
| }; | |
| function secRand(count) { | |
| const min = (-count >>> 0) % count; | |
| const rand = new Uint32Array(1); | |
| do { | |
| crypto.getRandomValues(rand); | |
| } while (rand[0] < min); | |
| return rand[0] % count; | |
| } | |
| function generateKeyboard(layout) { | |
| const target = 72; | |
| let rand = secRand(94); | |
| let bits = Math.log2(94); | |
| let char = String.fromCharCode(rand + 33); | |
| let pass = char; | |
| while(bits <= target) { | |
| const len = layout[char].length; | |
| bits += Math.log2(len); | |
| rand = secRand(len); | |
| char = layout[char][rand]; | |
| pass += char; | |
| } | |
| return pass; | |
| } | |
| console.log("Colemak pattern:", generateKeyboard(COLEMAK)); | |
| console.log("Dvorak pattern:", generateKeyboard(DVORAK)); | |
| console.log("QWERTY pattern:", generateKeyboard(QWERTY)); | |
| console.log("Workman pattern:", generateKeyboard(WORKMAN)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment