Skip to content

Instantly share code, notes, and snippets.

@lordsutch
lordsutch / test_bitmask.py
Created July 25, 2019 16:57
Bitmask testing routine for Python 3.6+
# Copyright (C) 2019 Chris Lawrence
# You may freely modify, copy, and reuse this software under the terms of the MIT License.
def test_bitmask(value: int, mask: str) -> bool:
mask = mask.replace("_", "")
testval: int = 1
for bit in reversed(mask):
if bit == '1' and not (value & testval):
return False
elif bit == '0' and (value & testval):
@lordsutch
lordsutch / randcaps.py
Created April 6, 2022 23:53
Randomly capitalize some text so you can be l33t on social media
#!/usr/bin/env python3
import argparse
import random
import sys
DEFAULT_PERCENTAGE = 40
def randcaps(text: str, percentage: float = DEFAULT_PERCENTAGE) -> str:
@lordsutch
lordsutch / diceware.py
Created August 6, 2025 04:44
Python 3.6+ code to automate the generation of Diceware passwords
#!/usr/bin/env python3
import argparse
import re
import secrets
import sys
WORDS = 7
# Can also use e.g. https://www.eff.org/deeplinks/2016/07/new-wordlists-random-passphrases
WORDLIST = 'diceware.wordlist.asc'