Question

Part 1 – Data Encryption Data Encryption is the process of transforming data, using a cipher,...

Part 1 – Data Encryption

Data Encryption is the process of transforming data, using a cipher, to make it unreadable to anyone except those possessing special knowledge. In this problem you will implement a simple encryption technique on data that comprises of non-negative integers that have at least six digits with no leading zeroes. In order to encrypt the number the following functions are to be implemented:
void input(int *num); int add4(int num); int shift(int num); void printOutput(int encryptNum, int originalNum);
The function input is used to read a positive integer having at least six digits and store it in the variable num. All leading zeroes in the input are neglected and are not counted as valid digits. The function will continue requesting for a number until a valid input is provided by the user. A sample run of the function is shown below with data entered by the user displayed using bold font.

Please enter an integer greater than 99999: 2348<enter> Incorrect input.

Please enter an integer greater than 99999: 012345<enter> Incorrect input.

Please enter an integer greater than 99999: 102345<enter> The number entered is 102345

The functions add4 and shift are used to encrypt the number. First, modify the value of each digit of num by adding 4 to the digit. The function add4 modifies the value of each digit of num by adding 4 to each digit,and returns the modified number. Due to addition,if the value of any digit is greater than 9 then subtract 10 from the number so that each digit ranges between 0 and 9. For example, if num is 345678 then add4 should return 789012. Note that the number of digits of the modified number returned by add4 can be less than the number of digits in num. For example, if num is 665325, then add4 returns 009769, which is really 9769.
The input (num) of the function shift is the modified number(output of the function add4). The function shift shifts the position of each digit to the left by one place. The most significant digit becomes the least significant digit.

For example,if the input (num)is 567890 then the output of the function shift is 678905. The modified value is returned by shift and is the final encrypted number. Similar to add4 function, the number of digits returned by shift can be less than the number of digits in num (input to function shift). For example, if num is 107982, then the encrypted number is 79821. The function printOutput prints the original number (originalNum) and the encrypted number (encryptNum). Refer to the examples below for the output format. You are allowed to use the math.h functions in your solution. Remember to add -lm to your gcc command line. Shown below are example runs of the program with data entered by the user displayed using bold font. Given the same user input, your output should match the output exactly, including all punctuation. Any variation from this will result in loss of marks.
• Example 1: Please enter an integer greater than 99999: 4569012<enter> The number entered is 4569012 Original number: 4569012 Encrypted number: 9034568
• Example 2: Please enter an integer greater than 99999: 563918<enter> The number entered is 563918 Original number: 563918 Encrypted number: 73529
• Example 3: Please enter an integer greater than 99999: 70912<enter> Incorrect input. Please enter an integer greater than 99999: 093679<enter> Incorrect input. Please enter an integer greater than 99999: 0877893<enter> The number entered is 877893 Original number: 877893 Encrypted number: 112372
Note: The encrypted number can have less than 6 digits (as shown in Example 2). It is up to the decryption technique to handle this (not part of this problem). In the case of Example 3, 0877893 is a valid input as it has 6 digits without any leading zero (877893)

Develop the code in C programming please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The required code is as follows:

#include <stdio.h>
#include <math.h>

void input(int *num) //function to input the number using its pointer
{
   printf("Please enter an integer greater than 99999: ");
   scanf("%d",num);
   if(*num<=99999)
   {
       printf("Incorrect input. ");
       input(num);
   }
   else
   {
       printf("The number entered is %d ",*num);
   }
}
int add4(int num) //function to add 4 to every digit of the number
{
   int c=1,a=0,r;
   while(num!=0) //we extract every digit from the number, add 4, make it single digit and store it in a
   {
       r=(num%10)+4;
       if(r>=10)
           r=r-10;
       a=a+r*c;
       num=num/10;
       c=c*10;
   }
   return a; //we return a to the main function
}
int shift(int num) //function to shift each digit of number to the left by one place
{
   int copy=num,r,c=1;
   while(copy!=0) //we use this loop to find the most significant bit and its place value(c)
   {
       r=copy%10;
       copy=copy/10;
       c=c*10;
   }
   num=num-(r*c/10); //we delete the most significant bit
   num=num*10+r; //we make it the least significant bit and shift the other digits to the left
   return num; //we return num to the main function
}
void printOutput(int encryptNum, int originalNum)
{
   printf("Original number : %d Encrypted number : %d ",originalNum,encryptNum);
}
int main(void) {
   int num;
   input(&num);
   printOutput(shift(add4(num)),num);
   return 0;
}

Screenshot of output:

Add a comment
Know the answer?
Add Answer to:
Part 1 – Data Encryption Data Encryption is the process of transforming data, using a cipher,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt...

    Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt a message is to use a date’s 6 digits to shift the letters. For example, if a date is picked as December 18, 1946, then the 6 digits are 121846. Assume the dates are in the 20th century. To encrypt a message, you will shift each letter of the message by the number of spaces indicated by the corresponding digit. For example, to encrypt...

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

  • This is to be written in C++. Thank you so much for you help as I'm...

    This is to be written in C++. Thank you so much for you help as I'm really struggling with this. Must be written in this format: #include <stdio.h> int main(void) { printf("Hello World\n"); return 0; } The explosive growth of Internet communications and data storage on Internet-connected computers has greatly increased privacy concerns. The field of cryptography is concerned with coding data to make it difficult (and hopefully—with the most advanced schemes—impossible) for unauthorized users to read. In this exercise,...

  • A company that wants to send data over the Internet has asked you to write a...

    A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first...

  • Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher...

    Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher is an encryption algorithm that encrypts 1 byte of plain text at a time. This one uses a given 4-bit bit pattern as the key. The size of the encrypted message that we want to be able to send has a maximum length of 200 characters. You must: 1. prompt the user to input the clear text to be encrypted. You must use printf()...

  • To use the digits function, enter 1 To use the average function, enter 2 To use the perfect sum f...

    use matlab To use the digits function, enter 1 To use the average function, enter 2 To use the perfect sum function, enter3 To exit the program, enter 4 Please select a number = 6 Please re-select again: 2 please enter the first number 3 please enter the second number: 6 please enter the third number: 3 The average equals to: 4 Write a function, called digits function that is able to calculate the number of digits and the summation...

  • PRG255 3.2 (2 marks) Write a C program that uses the bitwise shift operators to shut...

    PRG255 3.2 (2 marks) Write a C program that uses the bitwise shift operators to shut the The program will ask the user to enter an unsigned also how many bits for the shift operation. Display the entered operation in both decimal and binary formats, vise shirt operators to shift the bits to the right >> or the left << user to enter an unsigned integer number, choose right shift or left shift, and orauon. Display the entered number and...

  • Programming Problem HW1 Question 1

    Write a function createNum() that takes as a parameter an integer n, builds an n -digit integer using input from the user, and returns the integer. The function repeatedly prompts the user to enter single, positive (>0) digits and creates a number out of them, with the first valid digit entered being the most significant and the last valid digit entered being the least significant. If the user enters a zero, a negative number, more than one digit, or anything...

  • Have you ever noticed the bar code printed on envelopes? That code helps the USPS process...

    Have you ever noticed the bar code printed on envelopes? That code helps the USPS process the mail. The barcode is generated as specified below. In this assignment you are to write a JAVA program that will accept a 5 digit number from the user and then prints the appropriate symbols to the screen. Name your file ZipCode_yourInitials.java. The specifications for the code are PostalCodeAsignment.pdf. Using a do while loop allow the user to continue entering numbers as long as...

  • c++ pleased Assignment 6a (15 points] - Character and String related processing... Listed below are two...

    c++ pleased Assignment 6a (15 points] - Character and String related processing... Listed below are two interesting programming challenges that will require a bit of character and/or string related processing with functions. (Carefully read the specifications for each programming challenge and select ONE.) (1) Sum of Digits in a String Write a program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT