-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.py
More file actions
126 lines (107 loc) · 3.85 KB
/
utils.py
File metadata and controls
126 lines (107 loc) · 3.85 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# This file is part of 'NTLM Authorization Proxy Server'
# Copyright 2001 Dmitry A. Rozmanov <dima@xenon.spb.ru>
#
# NTLM APS is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# NTLM APS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with the sofware; see the file COPYING. If not, write to the
# Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
import string
hd = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',]
#--------------------------------------------------------------------------------------------
def str2hex_num(str):
res = 0L
for i in str:
res = res << 8
res = res + long(ord(i))
return hex(res)
#--------------------------------------------------------------------------------------------
def str2hex(str, delimiter=''):
res = ''
for i in str:
res = res + hd[ord(i)/16]
res = res + hd[ord(i) - ((ord(i)/16) * 16)]
res = res + delimiter
return res
#--------------------------------------------------------------------------------------------
def str2dec(str, delimiter=''):
res = ''
for i in str:
res = res + '%3d' % ord(i)
res = res + delimiter
return res
#--------------------------------------------------------------------------------------------
def hex2str(hex_str):
res = ''
for i in range(0, len(hex_str), 2):
res = res + (chr(hd.index(hex_str[i]) * 16 + hd.index(hex_str[i+1])))
return res
#--------------------------------------------------------------------------------------------
def str2prn_str(bin_str, delimiter=''):
""
res = ''
for i in bin_str:
if ord(i) > 31: res = res + i
else: res = res + '.'
res = res + delimiter
return res
#--------------------------------------------------------------------------------------------
def byte2bin_str(char):
""
res = ''
t = ord(char)
while t > 0:
t1 = t / 2
if t != 2 * t1: res = '1' + res
else: res = '0' + res
t = t1
if len(res) < 8: res = '0' * (8 - len(res)) + res
return res
#--------------------------------------------------------------------------------------------
def str2lst(str):
res = []
for i in str:
res.append(ord(i))
return res
#--------------------------------------------------------------------------------------------
def lst2str(lst):
res = ''
for i in lst:
res = res + chr(i & 0xFF)
return res
#--------------------------------------------------------------------------------------------
def int2chrs(number_int):
""
return chr(number_int & 0xFF) + chr((number_int >> 8) & 0xFF)
#--------------------------------------------------------------------------------------------
def bytes2int(bytes):
""
return ord(bytes[1]) * 256 + ord(bytes[0])
#--------------------------------------------------------------------------------------------
def int2hex_str(number_int16):
""
res = '0x'
ph = int(number_int16) / 256
res = res + hd[ph/16]
res = res + hd[ph - ((ph/16) * 16)]
pl = int(number_int16) - (ph * 256)
res = res + hd[pl/16]
res = res + hd[pl - ((pl/16) * 16)]
return res
#--------------------------------------------------------------------------------------------
def str2unicode(string):
"converts ascii string to dumb unicode"
res = ''
for i in string:
res = res + i + '\000'
return res