Skip to content

Instantly share code, notes, and snippets.

@dwf
Created August 28, 2018 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwf/f7f0f2648c30ad931fb4fe178268a744 to your computer and use it in GitHub Desktop.
Save dwf/f7f0f2648c30ad931fb4fe178268a744 to your computer and use it in GitHub Desktop.
Autofill CoventryBS's silly 2FA with Bitwarden regex custom fields.
"""
Take in a CoventryBS grid card as a text file, output regex custom fields for
Bitwarden to autofill your grid card challenge for you.
"""
from __future__ import print_function
import fileinput
import itertools
import sys
COLS = 'ABCDEFGHIJ'
ROWS = range(1, 6)
if __name__ == "__main__":
numbers = [l.strip().split() for l in fileinput.input()
if len(l.strip().split()) > 0]
if len(numbers) != 5 or any(len(n) != 10 for n in numbers):
print('ERROR: Expected a 5 rows x 10 columns grid of numbers.')
sys.exit(1)
by_value = {}
for (r, c), v in zip(itertools.product(ROWS, COLS), sum(numbers, [])):
by_value.setdefault(v, []).append('%s%d' % (c, r))
print("Use these as the keys for your Bitwarden custom fields, "
"with values 0-9\n")
for k in sorted(by_value):
print('regex=^(' + '|'.join(sorted(by_value[k])) + ').*')
print("\nI found it easiest to copy and paste into the notes and "
"then copy and paste to create each individual field.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment