Randomiser

A simple Alfred workflow to garble alphanumeric characters.

— Binary Adventures

More often than not, I need to share output that contains sensitive information (hostnames, usernames, …). To be able to safely share this data, I needed an easy and relatively safe way to garble the data.

Once again, the heroic duo Alfred and Python to the rescue! Alfred is used to retrieve the data from the clipboard (only text is supported, obviously), while the Python code below creates a mapping for all alphanumerical characters. Upper and lowercase are maintained, letters remains letters and the same goes for numbers. The mapping is randomised, so you’ll get a different output with each run. When finished, the garbled data is copied back to the clipboard.

This is what the complete workflow looks like:

And here’s the code that performs the garbling:

import sys
import string
import random

input_data = """{query}"""

trans_from = ''
trans_to = ''

for charset in (string.ascii_lowercase, string.ascii_uppercase, string.digits):
    trans_from += charset
    trans_to += ''.join(random.sample(charset, k=len(charset)))

sys.stdout.write(input_data.translate(string.maketrans(trans_from, trans_to)))

Remark: the Python code is version 2 syntax, because Alfred still points to the Python2 binary.

Below is an example of original and garbled data side-by-side (only the JSON values were garbled, not the keys):

Original Garbled
{
  "markers": [
    {
      "name": "Google, 8th Avenue",
      "position": [40.7414728,-74.0055813],
    },
    {
      "name": "Microsoft, Times Square",
      "location": [40.7565323,-73.9904037]
    }
  ]
}
{
  "markers": [
    {
      "name": "Svvzua, 0ld Cgaqba",
      "position": [54.8595870,-85.4433092],
    },
    {
      "name": "Fsfwvevml, Esjae Hhbpwa",
      "location": [54.8313272,-82.6645428]
    }
  ]
}

The packaged .alfredworkflow file is available here.