Created
August 25, 2013 08:36
-
-
Save funkybob/6332718 to your computer and use it in GitHub Desktop.
My Vigenere ciper for CSRF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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