Skip to content

Instantly share code, notes, and snippets.

@Tony3-sec
Last active January 25, 2018 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tony3-sec/72ddc9345358654cf571b5cd70839c8f to your computer and use it in GitHub Desktop.
Save Tony3-sec/72ddc9345358654cf571b5cd70839c8f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import urllib
import sys
import argparse
import os
'''
This script may (not) decode URL encodings with Unicode chars.
Ensure to set your editor / terminal's char encoding setting to UTF-8
in order to get proper output
'''
def decode_string(string_data):
print(urllib.unquote(string_data))
def decode_file(file_data):
path = os.getcwd()
filename = file_data
f = open((path + str('/') + filename), 'r')
d = open('decoded.txt', 'w')
while True:
line = f.readline()
if not line:
print('Also check "decoded.txt"')
f.close()
d.close()
break
print(urllib.unquote(line))
d.write(urllib.unquote(line))
parser = argparse.ArgumentParser(description="Decode URL encoded data")
parser.add_argument("-s", "--string", action="store", help="String to decode", dest="STRING")
parser.add_argument("-f", "--file", action="store", help="Decode from file", dest="FILE")
args = parser.parse_args()
if args.STRING:
decode_string(sys.argv[2])
elif args.FILE:
decode_file(sys.argv[2])
else:
parser.print_help()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment