Skip to content

Instantly share code, notes, and snippets.

@SkypLabs
Last active December 1, 2019 22:10
Show Gist options
  • Save SkypLabs/43de211858c8eadcd8be7af371daed1b to your computer and use it in GitHub Desktop.
Save SkypLabs/43de211858c8eadcd8be7af371daed1b to your computer and use it in GitHub Desktop.
Convert a string into character codes

String to character codes

This small Python script converts a string into character codes.

JavaScript XSS payload

Character codes are useful in XSS payloads when single and/or double quote characters can't be used to surround a string (escaped or removed from the payload). The JavaScript method String.fromCharCode() converts back the character codes into a string.

Example:

String.fromCharCode(79, 80, 69, 78, 66, 85, 71, 66, 79, 85, 78, 84, 89);
#!/usr/bin/env python3
from argparse import ArgumentParser
def get_arg_parser():
"""
Returns the argument parser.
"""
arg_parser = ArgumentParser(
description="Converts a string into char codes"
)
arg_parser.add_argument(
"string",
help="the string to convert"
)
return arg_parser
def main():
"""
Main function.
"""
args = get_arg_parser().parse_args()
string = args.string
result = []
for c in string:
result.append(ord(c))
print(result)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment