mirror of https://github.com/dirtbags/netarch.git
Refined XorMask
This commit is contained in:
parent
f52666a4c9
commit
9949fc600c
|
@ -87,7 +87,7 @@ def bin(i):
|
||||||
s = ''.join(str(x) for x in r)
|
s = ''.join(str(x) for x in r)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
class bitvector:
|
class BitVector:
|
||||||
def __init__(self, i=0, length=None):
|
def __init__(self, i=0, length=None):
|
||||||
if type(i) == type(''):
|
if type(i) == type(''):
|
||||||
self._val = 0
|
self._val = 0
|
||||||
|
|
14
crypto.py
14
crypto.py
|
@ -214,21 +214,23 @@ def adds(txt):
|
||||||
|
|
||||||
|
|
||||||
class XorMask:
|
class XorMask:
|
||||||
def __init__(self, mask):
|
def __init__(self, mask, stick=False):
|
||||||
self.offset = 0
|
self.offset = 0
|
||||||
if type(mask) == type(''):
|
if type(mask) == type(''):
|
||||||
self._mask = tuple(ord(m) for m in mask)
|
self._mask = tuple(ord(m) for m in mask)
|
||||||
else:
|
else:
|
||||||
self._mask = tuple(mask)
|
self._mask = tuple(mask)
|
||||||
|
self.stick = stick
|
||||||
|
|
||||||
def mask(self, s, stick=False):
|
def __call__(self, s):
|
||||||
r = []
|
r = []
|
||||||
|
offset = self.offset
|
||||||
for c in s:
|
for c in s:
|
||||||
o = ord(c)
|
o = ord(c)
|
||||||
r.append(chr(o ^ self._mask[self.offset]))
|
r.append(chr(o ^ self._mask[offset]))
|
||||||
self.offset = (self.offset + 1) % len(self._mask)
|
offset = (offset + 1) % len(self._mask)
|
||||||
if not stick:
|
if self.stick:
|
||||||
self.offset = 0
|
self.offset = offset
|
||||||
return ''.join(r)
|
return ''.join(r)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue