In: Computer Science
Write a C program
A simple method for encrypting data is that of ROT 13. The method takes each latin letter of plain text
and moves it to the next letter 13 times in latin alphabet (wrapping around if necessary). For those of
you who are unaware the latin alphabet is the following
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
This means the letter ‘a’ would become the letter ‘n’. The word “hello” would become “uryyb”. To
recover the original text you only need to apply ROT 13 to the encrypted text. The word “uryyb” under
ROT 13 becomes “hello”. Due to the simplicity of the encryption this method is no longer used in
practice.
Problem
For the first homework assignment of the semester you are to implement a similar encryption scheme
called ROT 13.5. In this encryption scheme whenever you encrypt a vowel (a, e, i, o, u) as plain text,
the next encrypted letter moves to the next letter 14 times in the latin alphabet. In all other cases a plain
text letter will be moved to the next letter 13 times. This means that the word “hello” becomes “urzyb”
under rot 13.5.
Input Specification
Input will start with a single positive integer n (n < 10). The next n lines contains a single word
consisting of lower case latin letters (no more than 100 characters in length). No extra whitespace will
be present.
Output Specification
For each word given in input your program is to output a line containing ONLY the word encrypted as
ROT 13.5 with no extra whitespace or characters in lowercase latin characters.
Code
#include<stdio.h>
#include<stdlib.h>
int main()
{
//variables
int n,i,j;
int vowelFlag=0;
//char pointer array
char *words[10],ch;
//taking first number from user
scanf("%d",&n);
//dynamiclly assign then memomry to the array
for (i = 0; i < n; i++)
words[i] = (char*)malloc((10) *
sizeof(char));
//taking words from the user
for (i = 0; i < n; i++)
scanf("%s",words[i]);
printf("\n\nEncrypted words are:\n");
for (i = 0; i < n; i++)
{
for(j = 0; words[i][j] != '\0';
j++)
{
ch =
words[i][j];
//check if the
char is vowel
if(ch == 'a' ||
ch == 'e' || ch=='i' || ch=='o' || ch=='u')
{
ch += 13;
vowelFlag=1;//then set vowelFlag to 1
}
else
{
if(vowelFlag==1)
{
ch+=14;
vowelFlag=0;
}
else
ch+=13;
}
if(ch >
'z')
ch = ch - 'z' + 'a' - 1;
words[i][j] =
ch;
}
printf("%s\n",words[i]);
}
return 1;
}
output
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.