textconv = "gpg --quiet -d"
[diff "sopsdiffer"]
textconv = "sops -d"
+[filter "anonymize"]
+ clean = "./scripts/anonymize -i words.json"
+ smudge = "./scripts/anonymize -i -d words.json"
+ required = true
+[submodule "nixops/secrets"]
+ url = gitolite@git.immae.eu:perso/Immae/Config/Nix/Nixops/Secrets
+ active = true
+[remote "origin-stgit"]
+ url = gitolite@git.immae.eu:perso/Immae/Config/Nix.stgit
+ push = +refs/stacks/*:refs/stacks/*
+ push = +refs/patches/*:refs/patches/*
+ push = +refs/original/*:refs/original/*
--- /dev/null
+#!/usr/bin/env python3
+
+import sys
+import argparse
+import os
+import json
+import re
+
+parser = argparse.ArgumentParser()
+parser.add_argument("words_file", help="File that contains the words to (de)anonymize")
+parser.add_argument("--ignore-missing", "-i", action="store_true", help="treat missing file as empty list")
+parser.add_argument("--deanonymize", "-d", action="store_true", help="deanonymize")
+config = parser.parse_args()
+
+alphabet="abcdefghijklmnopqrstuvwxyz"
+
+try:
+ key = os.environ["ANONYMIZE_KEY"].lower()
+ assert all([k in alphabet for k in key])
+except KeyError:
+ print("Please set ANONYMIZE_KEY as environment variable with only letters", file=sys.stderr)
+ sys.exit(1)
+
+if not os.path.isfile(config.words_file):
+ if config.ignore_missing:
+ print(sys.stdin.read(), end="")
+ sys.exit(0)
+ else:
+ print("Could not find words file", file=sys.stderr)
+ sys.exit(1)
+
+words = json.load(open(config.words_file))
+
+if any([len(word) > len(key) for word in words]):
+ print("The key needs to be at least as long as the longest word in the list (append to existing one to keep already mangled words)", file=sys.stderr)
+ sys.exit(1)
+
+order = -1 if config.deanonymize else 1
+
+def replace(match):
+ name = match.group()
+ result = []
+ for k in range(len(name)):
+ if name[k].lower() not in alphabet:
+ result.append(name[k])
+ else:
+ key_index = alphabet.index(key[k])
+ letter_index = alphabet.index(name[k].lower())
+ new_letter = alphabet[(letter_index + order * key_index) % len(alphabet)]
+ if name[k].lower() != name[k]:
+ new_letter = new_letter.upper()
+ result.append(new_letter)
+ return ''.join(result)
+
+regexp = re.compile("(" + '|'.join([r'(\b' + w + r'\b)' for w in words]) + ")")
+print(regexp.sub(replace, sys.stdin.read()), end="")