diff --git a/__init__.py b/__init__.py index f07d8b4..c57d2e9 100755 --- a/__init__.py +++ b/__init__.py @@ -87,7 +87,7 @@ def bin(i): s = ''.join(str(x) for x in r) return s -class bitvector: +class BitVector: def __init__(self, i=0, length=None): if type(i) == type(''): self._val = 0 diff --git a/crypto.py b/crypto.py index 32e826b..10df9c6 100644 --- a/crypto.py +++ b/crypto.py @@ -214,21 +214,23 @@ def adds(txt): class XorMask: - def __init__(self, mask): + def __init__(self, mask, stick=False): self.offset = 0 if type(mask) == type(''): self._mask = tuple(ord(m) for m in mask) else: self._mask = tuple(mask) + self.stick = stick - def mask(self, s, stick=False): + def __call__(self, s): r = [] + offset = self.offset for c in s: o = ord(c) - r.append(chr(o ^ self._mask[self.offset])) - self.offset = (self.offset + 1) % len(self._mask) - if not stick: - self.offset = 0 + r.append(chr(o ^ self._mask[offset])) + offset = (offset + 1) % len(self._mask) + if self.stick: + self.offset = offset return ''.join(r)