summaryrefslogtreecommitdiff
path: root/image_processing/xor.py
blob: 01050c3e2c73b18b4b2a8f5307ee5b0eda91993b (plain)
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
import sys
import math
from itertools import cycle

source, target, key = sys.argv[1:]

# key = [int(x) for x in key]

k = int(key, 2)

target = open(target,"ab")

with open(source, 'rb') as source:
    image_bytes = source.read()
    i = 0
    x = 0
    for n in image_bytes:
        if not (i == 3):
            x = n ^ k
            i += 1
        else:
            x = n
            i = 0
        target.write(bytes([x]))

target.close()