I am Zach Swiger
Also known as The Christronaut
A Freelance
Web Designer & Software Engineer
A real Christian, not a real Astronaut.
1 Corinthians 10:31
Ways I communicate
With Humans
With Computers
My C Projects
Here are a few of my C Programs, to see the entire collection visit my Github
Caesar Cipher
This C program implements a Caesar cipher. A Caesar cipher is a basic encryption technique where each letter in the plaintext is shifted a certain number of places down or up the alphabet. It is named after Julius Caesar, who is rumored to have used it to communicate with his generals. For example, with a shift of 3, ‘A’ would be replaced by ‘D’, ‘B’ would become ‘E’, and so on. The method wraps around the alphabet, so ‘X’ becomes ‘A’, ‘Y’ becomes ‘B’, and ‘Z’ becomes ‘C’. It’s a simple and easily breakable encryption method, but it was a fun way to introduce the concept of encryption.
(This was my solution to a CS50 problem set)
View Code
#include <cs50.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
bool only_digits(string key);
char rotate(int key_number, char plain_char);
int main(int argc, string argv[])
{
// check command line argument
if (argc != 2)
{
printf("Usage: caesar key\n");
return 1;
}
// set command line argument to a string called "key"
string key = argv[1];
// check that key is only numerical digits
if (!only_digits(key))
{
printf("Usage: ./caesar key\n");
return 1;
}
// convert key to int
int key_number = atoi(key);
// prompt user for plain text
string plain_text = get_string("plaintext: ");
// rotate plain characters into cipher characters
printf("ciphertext: ");
for (int i = 0, n = strlen(plain_text); i < n; i++)
if (isalpha(plain_text[i]))
{
if (isupper(plain_text[i]))
{
char plain_char = plain_text[i] - 'A';
char rotate_char = rotate(key_number, plain_char);
char new_char = rotate_char + 'A';
printf("%c", new_char);
}
if (islower(plain_text[i]))
{
char plain_char = plain_text[i] - 'a';
char rotate_char = rotate(key_number, plain_char);
char new_char = rotate_char + 'a';
printf("%c", new_char);
}
}
else
{
printf("%c", plain_text[i]);
}
printf("\n");
}
bool only_digits(string key)
{
// set variable to track status of truth
int non_digits = 0;
for (int i = 0, n = strlen(key); i < n; i++)
{
if (!isdigit(key[i]))
{
non_digits++;
}
}
if (non_digits > 0)
{
return false;
}
else
{
return true;
}
}
char rotate(int key_number, char plain_char)
{
char rotate_char = plain_char + key_number;
char wrap_char = rotate_char % 26;
return wrap_char;
}
Readability
This C program assesses how easy it is to read a piece of text provided by the user by looking at the number of letters, words and sentences. It calculates averages for the number of letters and sentences, per 100 words to create a readability score. Depending on this score it labels the text as “Grade 16+” for advanced “Before Grade 1” for simple or “Grade X” where X represents the approximate grade level needed to understand the text. This tool is helpful for measuring how complex written content is.
(This was my solution to a CS50 problem set)
View Code
#include <cs50.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
int count_letters(string text);
int count_sentences(string text);
int count_words(string text);
int main(void)
{
// prompt user for text
string text = get_string("Enter Text: ");
// count number of letters
int letters = count_letters(text);
// count number of words
int words = count_words(text);
// count number of sentences
int sentences = count_sentences(text);
// calculate readability
float float_letters = (float) letters;
float float_words = (float) words;
float float_sentences = (float) sentences;
float average_letters = (float_letters / float_words) * 100.0;
float average_sentences = (float_sentences / float_words) * 100.0;
int index = round((0.0588 * average_letters) - (0.296 * average_sentences) - 15.8);
// print readability level
if (index > 16)
{
printf("Grade 16+\n");
}
else if (index < 1)
{
printf("Before Grade 1\n");
}
else
{
printf("Grade %i\n", index);
}
}
int count_letters(string text)
{
// start counter for letters at 0
int letters = 0;
// count letters
for (int i = 0, n = strlen(text); i < n; i++)
{
if (isalpha(text[i]))
{
letters++;
}
}
return letters;
}
int count_words(string text)
{
// start counter for words at 1
int words = 1;
// count words
for (int i = 0, n = strlen(text); i < n; i++)
{
if (isblank(text[i]))
{
words++;
}
}
return words;
}
int count_sentences(string text)
{
// start counter for sentences at 0
int sentences = 0;
// count sentences
for (int i = 0, n = strlen(text); i < n; i++)
{
if (text[i] == '.')
{
sentences++;
}
if (text[i] == '?')
{
sentences++;
}
if (text[i] == '!')
{
sentences++;
}
}
return sentences;
}
Scrabble
Scrabble is a word game where players use letter tiles to create words on a game board and earn points based on the letters’ values.
This C program is a basic implementation of scrabble. It collects a word from two individuals and calculates their score based on Scrabble rules. Then it displays the winner.
View Code
#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
// create points
int points[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10};
int calculate_score(string word);
int main(void)
{
// prompt player 1 for a word
string word_1 = get_string("Player one type a word: ");
// prompt player 2 for a word
string word_2 = get_string("Player two type a word: ");
// calculate score of each word
int player_1_score = calculate_score(word_1);
int player_2_score = calculate_score(word_2);
// determine winner
// display the winner
if (player_1_score > player_2_score)
{
printf("Player 1 wins!\n");
}
else if (player_2_score > player_1_score)
{
printf("Player 2 wins!\n");
}
else
{
printf("It's a tie\n");
}
}
int calculate_score(string word)
{
// score counter
int score = 0;
// compute word score
for (int i = 0, n = strlen(word); i < n; i++)
{
if (islower(word[i]))
{
score += points[word[i] - 'a'];
}
if (isupper(word[i]))
{
score += points[word[i] - 'A'];
}
}
return score;
}
My Javascript Projects
Here are a few of my Javascript projects, to see the entire collection visit my Github
My Python Projects
Python projects will be added soon
Coming Soon
Coming Soon
View Code
projectStatus = coming soon
print(projectStatus)
Coming Soon
Coming Soon
View Code
projectStatus = coming soon
print(projectStatus)
Coming Soon
Coming Soon
View Code
projectStatus = coming soon
print(projectStatus)
My WordPress Projects
WordPress projects will be added soon
Looking for more information?
Can’t find what you’re looking for? Reach out to me.