Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To create 1 file: decoder-ring.c You should use the getchar library function to read console input one character at a time. The use of any

To create 1 file: decoder-ring.c

You should use the getchar library function to read console input one character at a time. The use of any other library functions for input is not recommended at this time.

Envision our decoder ring as a disk with the 26 upper-case alphabet letters arrayed around its edge in order, with a 27th place between 'Z' and 'A' containing a space. Each of the 27 slots has a number associated with it: the space is 0, 'A' is 1, 'B' is 2, and so on up to 'Z' = 26.

Assume a key value of zero, and a message of "Hello world!". The first letter 'H' has value 8. The key is 0, and there is no previous value, so 'H' will be encoded as 'H' (8 + 0 + 0 = 8 = 'H'). The second letter is 'e', which has value 5. The previous value plus 'e' plus the key is 'M' (8 + 5 + 0 = 13 = 'M'.) The third letter of the message is 'L'. (Note that we immediately convert lower-case letters to upper-case for this code.) Previous value 13 plus 'L' (12) plus key (0) = 25 = 'Y'. The fourth character is also 'L'. Previous value (25) plus 'L' (12) plus key (0) = 37, which when wrapped around the decoder ring (modulo 27) is 10, or 'J'.

The enciphered result for "Hello world!" is thus "HMYJYYUI LPP" with a key of 0, or "IOANCDAQIV A" with a key of 1, or "JQDRHJHYREKM" with a key of 2, and so on.

Newline characters (' ') are transmitted unencoded. Note that we treat spaces -- and all other non-alphabetic characters -- as value 0. They will be decoded as blank spaces.

This assignment can be completed using simple loop and conditional constructs, along with basic integer operations like addition and modulus. Your encoder-ring and decoder-ring programs should take an optional key value as a command-line argument. If no argument is given, the key is assumed to be 0. You may use the C library function atoi, or parse the command-line integer yourself. The encoder-ring reads in plaintext messages line by line and outputs ciphertext encrypted with the specified key. The decoder-ring reads in ciphertext as input and outputs the plaintext message decrypted with the specified key.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

3. What information do participants need?

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago