Skip to content

Instantly share code, notes, and snippets.

@funkybob
Created August 25, 2013 08:36
Show Gist options
  • Save funkybob/6332718 to your computer and use it in GitHub Desktop.
Save funkybob/6332718 to your computer and use it in GitHub Desktop.
My Vigenere ciper for CSRF
# If this were split out of the get_random_string def we
# we wouldn't need to repeat it here...
VALID_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
def mangle(token):
mask = get_random_string(len(token))
value = ''.join([
VALID_CHARS[ (VALID_CHARS.index(x) + VALID_CHARS.index(y)) % len(VALID_CHARS) ]
for x, y in zip(token, mask)
])
return '-'.join([value, mask])
def demangle(value):
value, mask = value.split('-')
return ''.join([
VALID_CHARS[ (VALID_CHARS.index(x) - VALID_CHARS.index(y)) % len(VALID_CHARS) ]
for x, y in zip(token, mask)
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment