This commit is contained in:
klein panic
2025-02-01 16:14:45 -05:00
commit 3aff0baacf
82 changed files with 1694 additions and 0 deletions

22
Caesar_Cipher/README.md Normal file
View File

@@ -0,0 +1,22 @@
# Caesar Cipher
## Description
This project implements a simple Caesar cipher to demonstrate basic encryption and decryption using a fixed shift value.
## Directory Structure
- `include/`: Contains the header files.
- `src/`: Contains the source code files (`main.c` and `caesar_cipher.c`).
- `obj/`: Contains the compiled object files.
- `build/`: Contains the Makefile and the compiled binary.
## How to Build
1. Navigate to the `build` directory.
2. Run `make` to compile the project.
## How to Run
1. After building, you will find an executable named `caesar_cipher` in the `build` directory.
2. Run it using `./caesar_cipher`.
## How to Clean
- Run `make clean` in the `build` directory to remove all compiled files.

View File

@@ -0,0 +1,27 @@
# Variables
CC = gcc
CFLAGS = -I../include -Wall -Wextra
OBJDIR = ../obj
SRCDIR = ../src
BINDIR = ../build
# Source files
SOURCES = $(SRCDIR)/main.c $(SRCDIR)/caesar_cipher.c
OBJECTS = $(OBJDIR)/main.o $(OBJDIR)/caesar_cipher.o
# Build target
TARGET = caesar_cipher
# Rules
all: $(BINDIR)/$(TARGET)
$(BINDIR)/$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -o $(BINDIR)/$(TARGET)
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJDIR)/*.o $(BINDIR)/$(TARGET)
.PHONY: all clean

BIN
Caesar_Cipher/build/caesar_cipher Executable file

Binary file not shown.

View File

@@ -0,0 +1,8 @@
#ifndef CAESAR_CIPHER_H
#define CAESAR_CIPHER_H
void encrypt(char *plaintext, int shift);
void decrypt(char *ciphertext, int shift);
#endif // CAESAR_CIPHER_H

Binary file not shown.

BIN
Caesar_Cipher/obj/main.o Normal file

Binary file not shown.

View File

@@ -0,0 +1,21 @@
#include "caesar_cipher.h"
#include <stdio.h>
#include <ctype.h>
void encrypt(char *plaintext, int shift) {
for (int i = 0; plaintext[i] != '\0'; i++) {
if (isalpha(plaintext[i])) {
char base = islower(plaintext[i]) ? 'a' : 'A';
plaintext[i] = (plaintext[i] - base + shift) % 26 + base;
}
}
}
void decrypt(char *ciphertext, int shift) {
for (int i = 0; ciphertext[i] != '\0'; i++) {
if (isalpha(ciphertext[i])) {
char base = islower(ciphertext[i]) ? 'a' : 'A';
ciphertext[i] = (ciphertext[i] - base - shift + 26) % 26 + base;
}
}
}

24
Caesar_Cipher/src/main.c Normal file
View File

@@ -0,0 +1,24 @@
#include "caesar_cipher.h"
#include <stdio.h>
int main() {
char message[256];
int shift;
printf("Enter a message to encrypt: ");
fgets(message, sizeof(message), stdin);
printf("Enter shift amount (1-25): ");
scanf("%d", &shift);
// Encrypt the message
encrypt(message, shift);
printf("Encrypted message: %s\n", message);
// Decrypt the message
decrypt(message, shift);
printf("Decrypted message: %s\n", message);
return 0;
}