summaryrefslogtreecommitdiff
path: root/and.py
blob: 7e6a35272a29d230607c8afa786bbc6385bf42cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from sys import argv

# Read two files as byte arrays
file1_b = bytearray(open(argv[1], 'rb').read())
file2_b = bytearray(open(argv[2], 'rb').read())

# Set the length to be the smaller one
size = len(file1_b) if len(file1_b) < len(file2_b) else len(file2_b)
andd_byte_array = bytearray(size)

# AND between the files
for i in range(size):
	andd_byte_array[i] = file1_b[i] & file2_b[i]

# Write the ANDd bytes to the output file	
open(argv[3], 'wb').write(andd_byte_array)

print(f"[*] {argv[1]} AND {argv[2]}\n[*] Saved to \033[1;33m{argv[3]}\033[1;m.")