#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
void encryptmessage1(char[][6]);
void encryptmessage2(char[][6]);
int
main()
{
char array[5][6] = {
{'A', 'B', 'C', 'D', 'E'},
{'F', 'G', 'H', 'I', 'J'},
{'K', 'L', 'M', 'N', 'O'},
{'P', 'Q', 'Z', 'R', 'S', 'T'},
{'U', 'V', 'W', 'X', 'Y'}
};
int choice;
printf("********************************\n");
printf("**ENCRYPTION/DECRYPTION SYSTEM**\n");
printf("********************************\n");
printf("\n");
printf("1.Code the message\n");
printf("2.Decode the message\n");
printf("3.EXIT\n");
printf("Make your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
encryptmessage1(array);
encryptmessage2(array);
break;
case 2:
// decrypt message
break;
default:
break;
}
return 0;
}
void
encryptmessage1(char array[][6])
{
int i, j, loop, k = 0, row, col, len = 0;
char str[80] = {};
char temparr[80] = {}; // temporary array
char temp;
printf("Please enter your message : ");
temp = getchar();
// reads string
while ((str[k] = getchar()) != '\n') {
k++;
}
i = 0;
// loop to temporary store values from another array
for (loop = 0; loop < 80; loop++) {
temparr[loop] = str[loop];
}
// Calculating length of the array
len = sizeof(str) / sizeof(str[0]);
// Checks for space character in array if its there then ignores it
// and swap str[i] to str[i+1];
for (i = 0; i < len; i++) {
if (str[i] == ' ') {
for (j = i; j < len; j++) {
str[j] = str[j + 1];
}
len--;
}
}
i = 0;
// from lowercase to uppercase
while (str[i] != '\n') {
if (islower(str[i])) {
str[i] = toupper(str[i]);
}
i++;
}
puts(str);
i = 0;
k = 0;
while (str[k] != '\n') {
for (row = 0; row < 5; row++) {
for (col = 0; col < 6; col++) {
if (str[k] == array[row][col]) {
temparr[i] = '0' + row;
temparr[i + 1] = '0' + col;
i += 2;
}
}
}
k++;
}
puts(temparr);
}
void
encryptmessage2(char array[][6])
{ int i, j, loop, k =0, row, col;
char key[80] = {};
char temparr2[80] = {}; // temporary array
char temp;
printf("Please enter your key : ");
temp = getchar();
// reads string
while ((key[k] = getchar()) != '\n') {
k++;
}
i = 0;
// loop to temporary store values from another array
for (loop = 0; loop < 80; loop++) {
temparr2[loop] = key[loop];
}
// array from lowercase to uppercase
while (key[i] != '\n') {
if (islower(key[i])) {
key[i] = toupper(key[i]);
}
i++;
}
//Printing the array with spaces using pointer
char *ptr = key;
if (*ptr) {
putchar(*ptr++);
while (*ptr) {
putchar(' ');
putchar(*ptr++);
}
}
}
[outputoftheproblem](https://i.stack.imgur.com/wLUGa.png)
If I type in the keyword cortina it just prints out ortina without the first letter I dont know if the problem is with the pointer Also any ideas how can I print out the same set of numbers which were encrypted from str[] as an array under the 'CORTINA' word like the example above:
C O R T I N A
1 1 0 0 3 4 0
3 4 5 6 3 2 5
2 3 4 5 6 7 8
2 3 4 3 2 4 5