/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
char text[64] = "The quick brown fox jumps over the lazy dog\0"; // Asking for the text-input
char argv[32] = "DWUSXNPQKEGCZFJBTLYROHIAVM";
int len = strlen(argv);
int i=0;
char temp = 0;
int index = 0;
printf("strlen(text): %ld strlen(argv) = %d\n ",strlen(text),len);
printf("ciphertext: ");
for(i = 0; i < strlen(text); i++) //loop for the given text length
{
if(isalpha(text[i]) == 0 && text[i] != '\0') //If not alphabet, then do nothing
{
printf("%c",text[i]);
continue;
}
temp = text[i];
if(temp >= 'A' && temp <= 'Z') // Check for UPPERCASE LETTERS and change according to key
{
temp +=32;
}
if(temp >= 'a' && temp <= 'z') //Check for LOWERCASE LETTERS and change according to key
{
index = (temp - 97)%len;
printf("%c",argv[index]);
}
}
printf("\n");
}