1# Makefile for File Encryption Examples
2# C Programming Project 7
3
4CC = gcc
5CFLAGS = -Wall -Wextra -std=c11 -O2
6TARGETS = simple_xor file_encrypt file_encrypt_v2
7
8.PHONY: all clean test
9
10all: $(TARGETS)
11
12# κΈ°λ³Έ XOR λ°λͺ¨
13simple_xor: simple_xor.c
14 $(CC) $(CFLAGS) $< -o $@
15
16# νμΌ μνΈν λꡬ (κΈ°λ³Έ)
17file_encrypt: file_encrypt.c
18 $(CC) $(CFLAGS) $< -o $@
19
20# νμΌ μνΈν λꡬ v2 (ν€λ + κ²μ¦)
21file_encrypt_v2: file_encrypt_v2.c
22 $(CC) $(CFLAGS) $< -o $@
23
24# ν
μ€νΈ μ€ν
25test: all
26 @echo "=== Testing simple_xor ==="
27 ./simple_xor
28 @echo ""
29 @echo "=== Testing file_encrypt ==="
30 @echo "Test message for encryption" > test.txt
31 ./file_encrypt -e test.txt test.enc mypassword
32 ./file_encrypt -d test.enc decrypted.txt mypassword
33 @diff -q test.txt decrypted.txt && echo "β Basic encryption test passed"
34 @rm -f test.txt test.enc decrypted.txt
35 @echo ""
36 @echo "=== Testing file_encrypt_v2 ==="
37 @echo "Advanced test with header validation" > test2.txt
38 ./file_encrypt_v2 encrypt test2.txt test2.enc strongpass
39 ./file_encrypt_v2 info test2.enc
40 ./file_encrypt_v2 decrypt test2.enc decrypted2.txt strongpass
41 @diff -q test2.txt decrypted2.txt && echo "β Advanced encryption test passed"
42 @echo ""
43 @echo "Testing wrong password (should fail):"
44 @./file_encrypt_v2 decrypt test2.enc wrong.txt wrongpass || echo "β Password validation working"
45 @rm -f test2.txt test2.enc decrypted2.txt wrong.txt
46 @echo ""
47 @echo "All tests passed!"
48
49clean:
50 rm -f $(TARGETS) *.o *.enc *.txt *.bin *.dec