forked from bl4de/security-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathed.py
More file actions
executable file
·96 lines (68 loc) · 1.88 KB
/
Copy pathed.py
File metadata and controls
executable file
·96 lines (68 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
"""ED encoder/decoder tools
bl4de | bloorq@gmail.com | Twitter: @_bl4de | H1: bl4de | GitHub: bl4de
Simple encoder/decoder tool
./ed.py [string to encode] [input encoding] [output encoding]
"""
import base64
import sys
import urllib
def __get_char_hex_value(c):
"""returns 61; for 'a' truncated from 0x61"""
return hex(ord(c)).replace("0x", "")
def to_base_64(s):
return base64.b64encode(s)
def from_base_64(s):
return base64.b64decode(s)
def url_encode(s):
return urllib.quote(s)
def to_ascii(s):
return s
def from_ascii(s):
return s
def from_hex(s):
xs = ""
decimals = s.split()
for d in decimals:
xs += str(int(d, 10))
return xs
def to_hex(s):
xs = ""
hexnums = s.split()
for d in hexnums:
hexnum = str(hex(int(d, 10))).replace("0x", "")
if len(hexnum) < 2:
hexnum = "0" + hexnum
xs += hexnum + " "
return xs
def to_html_entities(s):
xs = ""
for c in s:
entity = "�" + __get_char_hex_value(c) + ";"
if entity:
xs += entity
return xs
if __name__ == "__main__":
fn_map_from = {
"base64": from_base_64,
"ascii": from_ascii,
"hex": from_hex
}
fn_map_to = {
"base64": to_base_64,
"ascii": to_ascii,
"url": url_encode,
"hex": to_hex,
"html_entities": to_html_entities
}
if len(sys.argv) != 4:
print "usage: ed.py [string] [input] [output]" \
"\n\n input: base64, ascii, hex\n " \
"output: base64, ascii, url, hex, html_entities ( eg. )"
exit(0)
# f = open(sys.argv[1], "r")
# # TODO remove special chars - arg passing
# data = f.readline().replace("\\n", "")
data = sys.argv[1]
output = fn_map_from[sys.argv[2]](fn_map_to[sys.argv[3]](data))
print output