Question

Needs to be done in C,

The function shown can be called to reverse the char.

7.5 Bit Encryption 7.5.1 Problem Given a single character, apply a simple bitwise encryption algorithm and return the cipherachar bitreve(char c) { int reverse = @; int i = 0; char reversedc; for (i=0; i<8; i++) { reverse (reverse<<1)|(c&1); C = c>>

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

SOLUTION: The solution consist of two codes.

1)main code

2)user defined header file code

you can modify the main code if you wanyt.

codes.c FILE:

/* this program will ask the user to enter one character and 
then it will print the encrypted and decrypted results */

#include <stdio.h>
#include<conio.h>
//This header file includes two function one is to encrypt and other is for decrypt
#include "codes.h"
int main()
{
   char s[2],g;
   int n1;
   //Prompting the user for character
   printf("Enter the character:");
   scanf("%c",s);
   //calling encrypt function which is present in the user defined header file "codes.h"
   n1=encrypt(3,4,s[0]);
   printf("The encrypted output is %d\n",n1);
   //calling decrypt function which is present in the user defined header file "codes.h"
   g=decrypt(3,4,n1);
   printf("The decrypted output is %c\n",g);
    return 0;
}

LTE Web Admin х C Chegg х GDB online Debugger Compiler X New Tab х + c onlinegdb.com Language c Run Debug Stop Share Save { }

codes.h FILE:

/* this header file consist of two functions 1) encrypt() , 2) decrypt() */
int encrypt(int a,int b, char c)
{
    int reverse=0;
//reversing binary representation of character and converting it into integer    
    for(int i=0;i<8;i++)
    {
       reverse= (reverse<<1)|(c&1);
       c=c>>1;
    }
//Left-shifting the integer value by given amount of starting value
      reverse= reverse<<a;
//Right-shifting the integer value by given amount of offset value
      reverse= reverse>>b;
//returning the encrypt result(which is in integer forn)
      return reverse;
}
char decrypt(int a, int b, int c)
{
    int reverse=0;
//Right-shifting the integer value by given amount of offset value    
    c= c<<b; 
//Left-shifting the integer value by given amount of starting value    
    c= c>>a;
//reversing binary representation of integer and converting it into character
    for(int i=0;i<8;i++)
    {
     reverse= (reverse<<1)|(c&1);
       c=c>>1;
    }
//returning the decrypt result(which is character form)    
    char y=(char)reverse;
    return y;
}

LTE Web Admin х C Chegg х GDB online Debugger Compiler X + c onlinegdb.com Language c 9 reverse Run Debug Stop Share Save {}B

28 reverse (reverse<<1)|(c&1); 29 C=C>>1; 30 31 //returning the decrypt result(which is character form) 32 char y=(char)rever

SAMPLE OUTPUT:

LTE Web Admin х C Chegg х GDB online Debugger Compiler X + c onlinegdb.com input Enter the character:T The encrypted output i

LTE Web Admin Х C Chegg х GDB online Debugger Compiler X + c onlinegdb.com input Enter the character:s The encrypted output i

Add a comment
Know the answer?
Add Answer to:
Needs to be done in C, The function shown can be called to reverse the char....
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
  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • Write the programming C please, not C++. The main function should be to find the offset...

    Write the programming C please, not C++. The main function should be to find the offset value of the ciper text "wPL2KLK9PWWZ7K3ST24KZYKfPMKJ4SKLYOKRP4KFKP842LK0ZTY43 " and decrypt it. In cryptography, a Caesar Cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be...

  • C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher....

    C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher. cipher_sub (a, b, c, d) a is the string that has the data that will be encrypted or decrypted b is the string that has the result of the encrypt/decrypt c is the code string used for our substitution cipher (27 entries plus '\0' character) d is an integer that will pass two constants defined as ENC (encrypt) or DEC (decrypt) --> The function...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

  • This is Crypto Manager blank public class CryptoManager { private static final char LOWER_BOUND = '...

    This is Crypto Manager blank public class CryptoManager { private static final char LOWER_BOUND = ' '; private static final char UPPER_BOUND = '_'; private static final int RANGE = UPPER_BOUND - LOWER_BOUND + 1; /** * This method determines if a string is within the allowable bounds of ASCII codes * according to the LOWER_BOUND and UPPER_BOUND characters * @param plainText a string to be encrypted, if it is within the allowable bounds * @return true if all characters...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

  • Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is...

    Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is to create a program to encode files and strings using the caesar cipher encoding method. Information about the caesar method can be found at http://www.braingle.com/brainteasers/codes/caesar.php.   Note: the standard caesar cipher uses an offset of 3. We are going to use a user supplied string to calculate an offset. See below for details on how to calculate this offset from this string. First open caesar.cpp...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include...

    Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include <string.h> #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start: // You are given a partially complete program. Complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify the function return types or parameters. //...

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