Exemplo n.º 1
0
 def test_xor(self):
     self.assertEquals(xor(b'', b''), b'')
     self.assertEquals(xor(b'\x00', b'\x00'), b'\x00')
     self.assertEquals(xor(b'\x01', b'\x00'), b'\x01')
     self.assertEquals(xor(b'\x01\x01', b'\x00\x01'), b'\x01\x00')
     self.assertEquals(xor(b'banana', b'ananas'),
                       b'\x03\x0f\x0f\x0f\x0f\x12')
Exemplo n.º 2
0
 def _unprotect(self, string):
     """
     Base64 decode and XOR the given `string` with the next salsa.
     Returns an unprotected string.
     """
     tmp = base64.b64decode(string.encode("utf-8"))
     return xor(tmp, self._get_salsa(len(tmp))).decode("utf-8")
Exemplo n.º 3
0
 def _protect(self, string):
     """
     XORs the given `string` with the next salsa and base64 encodes it.
     Returns a protected string.
     """
     tmp = bytes(xor(string, self._get_salsa(len(string))))
     return base64.b64encode(tmp)
Exemplo n.º 4
0
 def _unprotect(self, string):
     """
     Base64 decode and XOR the given `string` with the next salsa.
     Returns an unprotected string.
     """
     tmp = base64.b64decode(string)
     return bytes(xor(tmp, self._get_salsa(len(tmp))))
Exemplo n.º 5
0
 def _protect(self, string):
     """
     XORs the given `string` with the next salsa and base64 encodes it.
     Returns a protected string.
     """
     encoded = string.encode("utf-8")
     tmp = xor(encoded, self._get_salsa(len(encoded)))
     return base64.b64encode(tmp).decode("utf-8")
Exemplo n.º 6
0
 def _protect(self, string):
     """
     XORs the given `string` with the next salsa and base64 encodes it.
     Returns a protected string.
     """
     encoded = string.encode("utf-8")
     tmp = xor(encoded, self._get_salsa(len(encoded)))
     return base64.b64encode(tmp).decode("utf-8")
Exemplo n.º 7
0
 def test_xor(self):
     self.assertEquals(xor(b'', b''), b'')
     self.assertEquals(xor(b'\x00', b'\x00'), b'\x00')
     self.assertEquals(xor(b'\x01', b'\x00'), b'\x01')
     self.assertEquals(xor(b'\x01\x01', b'\x00\x01'), b'\x01\x00')
     self.assertEquals(xor(b'banana', b'ananas'), b'\x03\x0f\x0f\x0f\x0f\x12')