Experimental polybius square encryption
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
polybius-square/decrypt_screen.c

346 lines
6.7 KiB

/* decrypt_screen.c
This function is part of the Polysqu program. It decrypts user input and
writes it to the screen.
Copyright (C) 2015, 2016 Scott C. MacCallum
scm@ma.sdf.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void decrypt_screen(void)
{
int index;
int element_number = 1;
int array_number[5];
int element_letter = 97;
int array_letter[25];
int counter_outside;
int array_input[3];
int counter_inside;
char letter;
printf("\n");
printf("Your message will be decrypted using this\n");
printf("Polybius Square.\n");
/* At index zero, initialize the elements in the array of numbers
with values one through five */
for (index = 0; element_number < 6; index++)
array_number[index] = element_number++;
printf("\n");
printf(" ");
/* At index zero, print the values of the elements in the array of
numbers */
for (index = 0; index < 5; index++)
printf("%d ", array_number[index]);
printf("\n");
/* At index zero, print the value of the element in the array of
numbers */
printf("%d ", array_number[0]);
/* At index zero, initialize the elements in the array of letters
with ASCII values ninety-seven through one hundred twenty-one */
for (index = 0; element_letter < 122; index++)
array_letter[index] = element_letter++;
/* At index zero, print the five ASCII values of the elements in
the array of letters */
for (index = 0; index < 5; index++)
printf("%c ", array_letter[index]);
printf("\n");
/* At index one, print the ASCII value of the element in the
array of numbers */
printf("%d ", array_number[1]);
/* At index five, print the five ASCII values of the elements in
the array of letters */
for (index = 5; index < 10; index++)
printf("%c ", array_letter[index]);
printf("\n");
/* At index two, print the ASCII value of the element in the
array of numbers */
printf("%d ", array_number[2]);
/* At index ten, print the five ASCII values of the elements in
the array of letters */
for (index = 10; index < 15; index++)
printf("%c ", array_letter[index]);
printf("\n");
/* At index three, print the ASCII value of the element in the
number array */
printf("%d ", array_number[3]);
/* At index fifteen, print the five ASCII values of the elements
in the letter array */
for (index = 15; index < 20; index++)
printf("%c ", array_letter[index]);
printf("\n");
/* At index four, print the ASCII value of the element in the
number array */
printf("%d ", array_number[4]);
/* At index twenty, print the five ASCII values of the elements
in the letter array */
for (index = 20; index < 25; index++)
printf("%c ", array_letter[index]);
printf("\n");
printf("\n");
printf
("Limit your encrypted message to one hundred fifty numbers;\n");
printf("end it with an exclamation point.\n");
printf("\n");
printf("Encrypted Message: ");
for (counter_outside = 0; counter_outside < 77; counter_outside++) {
scanf("%d", &array_input[0]);
scanf("%d", &array_input[1]);
/* a */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[0]) {
printf("Decrypted Message: ");
for (counter_inside = 0;
counter_inside <= counter_outside;
counter_inside++) {
putchar(array_letter[0]);
}
printf("\n");
printf("\n");
printf("Encrypted Message: ");
}
/* b */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[0]) {
}
/* c */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[0]) {
}
/* d */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[3]) {
}
/* e */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[3]) {
}
/* f */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[5]) {
}
/* g */
if (array_input[0] == array_number[0]
&& array_input[2] == array_number[0]) {
}
/* h */
if (array_input[0] == array_number[0]
&& array_input[2] == array_number[1]) {
}
/* i */
if (array_input[0] == array_number[0]
&& array_input[2] == array_number[2]) {
}
/* j */
if (array_input[0] == array_number[0]
&& array_input[2] == array_number[3]) {
}
/* k */
if (array_input[0] == array_number[0]
&& array_input[2] == array_number[4]) {
}
/* l */
if (array_input[0] == array_number[0]
&& array_input[2] == array_number[5]) {
}
/* m */
if (array_input[0] == array_number[0]
&& array_input[3] == array_number[1]) {
}
/* n */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* o */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* p */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* q */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* r */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* s */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* t */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* u */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* v */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* w */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* x */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* y */
if (array_input[0] == array_number[0]
&& array_input[1] == array_number[1]) {
}
/* ! */
if (letter == '!') {
printf("\n");
exit(0);
}
if (counter_outside == 76) {
printf("\n");
printf("\n");
printf("ERROR, bad input.");
printf("\n");
printf("\n");
exit(1);
}
}
}