Question

In: Computer Science

2. Implement a decoder for the encoding scheme used in the first problem. The decoder will...

2. Implement a decoder for the encoding scheme used in the first problem. The decoder will reverse whatever operation was performed on the string, meaning each character will be rotated 3 to the left. For example, the input string def will decode to abc. Create a program which implements this decoding scheme and allows the user to input a string to be decoded. • Only use ASCII characters in range [32, 127]. • Read an entire string of input from the user using fgets. • Use input prompt "Enter a string: ". • Remove the trailing newline character from the string. • Encode the string using the scheme described above. • Output ONLY the decoded message on a new line. • Save your code as decoder.c.

How to write this in C language

Solutions

Expert Solution

//IF YOU ARE SATISFIED WITH THE CODE, KINDLY LEAVE A LIKE, ELSE COMMENT TO CLEAR DOUBTS. PLEASE DO NOT DOWN VOTE WITHOUT ANY REASON, IF I CANNOT CLARIFY THEN DOWNVOTE

CODE:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char string[50];
printf("\nEnter the string to be decoded: ");
fgets(string, 100, stdin);
int size = strlen(string) -1;
int k;
for (int i = 0; i < size; i++)
{
k = (int)(string[i]);
k -= 3;
if (k < 32)
{
k = 127 - (32 - k);
}
string[i] = (char)k;
}
printf("\nDecoded -> %s", string);
return 0;
}

OUTPUT:


Related Solutions

Problem 2 (C++): Design and implement a class complexType, that can be used to process complex...
Problem 2 (C++): Design and implement a class complexType, that can be used to process complex numbers. A number of the form a +ib, in which i2 = -1 and a and b are real numbers, is called a complex number. We call a the real part and b the imaginary part of a + ib. Complex numbers can also be represented as ordered pairs (a, b). The class you will design should have the following features. Constructor Your class...
Code a 2:4 decoder with registered out. Also write a testbench of the decoder.
Code a 2:4 decoder with registered out. Also write a testbench of the decoder.
Implement the following function using a binary decoder and as few NAND gates as possible. F=...
Implement the following function using a binary decoder and as few NAND gates as possible. F= A’B’C’D’ + A’B’C D’ + A’BCD’ + AB’CD’ + ABC’D’ + ABCD’ a) Draw the truth table for the function. (8 Pts) b) Implement the function using only one 74x138 decoder and as few NAND gates as possible. Clearly name all the signals in accordance with the documentation standards. (12 Pts) b) Implement the function using only one 74x138 decoder and as few NAND...
Question: Rotate and sort the list:-   In this problem, you have to first implement a singly...
Question: Rotate and sort the list:-   In this problem, you have to first implement a singly linked list whose each node should have the following attributes, ● key - a positive integer ● next - address/pointer/reference to the next node in the linked list You will receive Q1 queries of following types, ● 1 x - Append a node to the linked list whose key should be x. After appending, print, in a new line, the key of each node...
Given a network topology and three routers and an IPv4 or IPv6 addressing scheme, implement the...
Given a network topology and three routers and an IPv4 or IPv6 addressing scheme, implement the correct routing protocol and confirm layer connectivity.
in C++ We are going to implement the following scheduling algorithms 1. First-Come First-Served (FCFS) 2....
in C++ We are going to implement the following scheduling algorithms 1. First-Come First-Served (FCFS) 2. Shortest Remaining Time First (SRTF) 3. Highest Response Ratio Next (HRRN) 4. Round Robin, with di_erent quantum values (RR) We are interested to compute the following metrics, for each experiment: _ The average turnaround time _ The total throughput (number of processes done per unit time) _ The CPU utilization _ The average number of processes in the ready queue The simulator needs to...
Run Length Encoding It is sometimes important to minimise the space used for storing data. This...
Run Length Encoding It is sometimes important to minimise the space used for storing data. This idea of data compression can be implemented in many forms. One of the simpler techniques is known as Run Length Encoding (RLE). RLE takes advantage of the fact that in many cases, data will contain a run of repeated 0s or 1s, and these runs can be represented by a shorter code. RLE is a technique used in some image or sound formats to...
Some of the encoding techniques used over fiber are Manchester, 4B5B, and 8B10B. What are these...
Some of the encoding techniques used over fiber are Manchester, 4B5B, and 8B10B. What are these encoding methods?
C++ problem 11-2 In this chapter, the class dateType was designed to implement the date in...
C++ problem 11-2 In this chapter, the class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the member variables. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and year are checked before storing the date into the member variables. Add a member function, isLeapYear, to check whether...
Given a network topology of 3 or more routers with an OSPF addressing scheme, implement single-area...
Given a network topology of 3 or more routers with an OSPF addressing scheme, implement single-area OSPF routing.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT