Skip to content

Instantly share code, notes, and snippets.

@rvprasad
Last active May 5, 2018 20:41
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rvprasad/46d2f7b086c02fcedfea3b7ec970d0ff to your computer and use it in GitHub Desktop.
Anonymizes the names (in names.txt) without disturbing the order and frequency of alphabet and number positions
from random import randrange, sample, shuffle
alphas = list('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
nums = list('1234567890')
shuffle(alphas)
shuffle(nums)
def scramble(s, seen):
while True:
ret = ''.join([(nums[int(x)] if x in nums else
alphas[randrange(0, len(alphas))]) for x in s])
if (ret not in seen):
seen.add(ret)
return ret
with open("names.txt", "rt") as f:
seen = set()
for l in [x.strip() for x in f.readlines()]:
print(scramble(l, seen))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment