-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdtxor.py
More file actions
26 lines (20 loc) · 673 Bytes
/
dtxor.py
File metadata and controls
26 lines (20 loc) · 673 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from dtoperation import DTOperation
class DTXor(DTOperation):
'''Return XORd input as output'''
def needs_key(self):
''''''
return True
def needs_second_key(self):
''''''
return False
def needs_IV(self):
''''''
return False
def transform(self, dt_input, dt_key1=None, dt_key2=None, dt_iv=None, dt_mode='dec'):
'''Return input as output.'''
dt_output = bytearray(len(dt_input))
for i, current_byte in enumerate(str(dt_input)):
dt_output[i] = ord(current_byte) ^ ord(dt_key1[i % len(dt_key1)])
return dt_output