Question

In: Computer Science

Write a C program A simple method for encrypting data is that of ROT 13. The...

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.

Solutions

Expert Solution

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.


Related Solutions

Write the program in java Write a program that does basic encrypting of text. You will...
Write the program in java Write a program that does basic encrypting of text. You will ask the user the filename of a text file which contains a few sentences of text. You will read this text file one character at a time, and change each letter to another one and write out to an output file. The conversion should be done a -> b, b->c , … z->a, A->B, B->C, …. Z->A. This means just shift each letter by...
Encrypting Text with a Caesar Cipher Write a C program caesar.c which reads characters from its...
Encrypting Text with a Caesar Cipher Write a C program caesar.c which reads characters from its input and writes the characters to its output encrypted with a Caesar cipher. A Caesar cipher shifts each letter a certain number of positions in the alphabet. The number of positions to shift will be given to your program as a command line argument. Characters other than letters should not be encrypted. Your program should stop only at the end of input. Your program...
This is c++. The goal is to test each method function by writing a simple program...
This is c++. The goal is to test each method function by writing a simple program displaying how they work in int main . #ifndef ARRAY_FUNCTIONS_H #define ARRAY_FUNCTIONS_H #include <iostream> #include <iomanip> using namespace std; template <typename T> class Array_functions { public: int size; int cap; int* ptr; //default ctor Array_functions(); // ctor with one arg Array_functions(int size); //allactes a dynamic array T* allocate(int n); //resizes array onto another T* resize_arr(T *dest,int old_cap, int new_cap); //deletes array void delete_arr(T& a);...
Needs to be in basic JAVA Write a program that does basic encrypting of text. You...
Needs to be in basic JAVA Write a program that does basic encrypting of text. You will ask the user the filename of a text file that contains a few sentences of text. You will read this text file one character at a time, and change each letter to another one and write out to an output file. The conversion should be done a -> b, b->c , … z->a, A->B, B->C, …. Z->A. This means just shift each letter...
Write a code for simple racing game (using dots) on c program.
Write a code for simple racing game (using dots) on c program.
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
Write a C++ program that implements a simple scanner for a source file given as a...
Write a C++ program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described below. You may assume that the input is syntactically correct. Optionally, your program can build a symbol table (a hash table is a good choice), which contains an entry for each token that was found in the input. When all the input has been read, your program should produce a summary report that includes a...
Using C Write a program that will serve as a simple shell. This shell will execute...
Using C Write a program that will serve as a simple shell. This shell will execute an infinite for loop. In each iteration of the loop, the user will be presented with a prompt. When the user enters a command, the shell will tokenize the command, create a child process to execute it and wait for the child process to be over. If the user enters an invalid command, the shell should recognize the situation and show a meaningful message....
For this assignment you will develop pseudocode and write a C++ program for a simple calculator....
For this assignment you will develop pseudocode and write a C++ program for a simple calculator. You will create both files in Codio. Put your pseudocode and C++ code in the files below. PSEUDOCODE FILE NAME: Calculator.txt C++ SOURCE CODE FILE NAME : Calculator.cpp DESCRIPTION: Write a menu-driven program to perform arithmetic operations and computations on a list of integer input values. Present the user with the following menu. The user will choose a menu option. The program will prompt...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT