Question
In C Programming; A simple way to encrypt a number is to replace each digit of the number with its position (index) in a key
In C Programming;
A simple way to encrypt a number is to replace each digit of the number with its position (index) in a key array. A key array is an ordering of the digits 0 9, such as 2 3 1 9 8 4 7 5 6 0. For example, 831 will be encrypted as 412 with the key array 2 3 1 9 8 4 7 5 6 0 because 8 is at position (index) 4 in the key array, 3 is at index 1, 1 is at index 2. Write a C program that asks the user to enter a positive integer (the integer could be of any number of digits in the range of the integer type) and encrypts the number with a key array thats randomly generated.
sample input/output:
Enter the number of digits of the number: 5 Enter the number: 92028 Key array: 2 3 1 9 8 4 7 5 6 0 Output: 30904
Requirements: 1) The user will enter the total number of digits before entering the number. You can use format specifier "%1d" in scanf to read in a single digit into a variable (or an array element). For example, for input 101011, scanf("%1d", &num) will read in 1 to num. 2) Include the swap function from part 1 to generate the key array. 3) As part of the solution, write and call the function replace() with the following prototype. The replace() function assumes that the digits are stored in the array a and computes the replaced digits and store them in the array b. The function uses the key array key to encrypt. n represents the size of the array a and b. void replace(int a[], int b[], int key[], int n); 4) The main function reads in the input and stores it in an array, calls swap function to generate the key array, and calls the replace function, and then displays the output.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started