Skip to content

Instantly share code, notes, and snippets.

@navicore
Created October 16, 2014 17:28
Show Gist options
  • Save navicore/e81c3f409eeb5744ced2 to your computer and use it in GitHub Desktop.
Save navicore/e81c3f409eeb5744ced2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import csv
# tabbed file tabs.txt:
#one two three four
# cmd:
#cat tabs.txt | ./mask.py 2 CUSTOMER_
POS = int(sys.argv[1])
LABEL = sys.argv[2]
def checksum256(start):
""" checksum """
return reduce(lambda x, y:x+y, map(ord, start)) % 256
CF = csv.reader(sys.stdin, delimiter='\t')
for row in CF:
row[POS] = LABEL + str(checksum256(row[1])).zfill(3)
print '\t'.join(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment