Question

Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher is an encryption algor

enter cleartext: two fat dogs Text entered is: two fat dogs Hex encoding is: 74 77 6F 20 66 61 74 20 64 6F 67 73 enter 4-bit

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

code is :---

------------------------------------------------------------------------------------------------------

#include<stdio.h>
#include<string.h>

int main(){

char text[200];// text

char c;
printf("enter cleartext:");
int pos=0;
while(c!='\n'){
c =getchar();
text[pos]=c;
pos++;
}
printf("\nText entered is:%s",text);
  

c='c'; // to make c not equal to \n.. 'c' is arbitray
int n=pos-1;// length of the text
printf("\nHex encoding is:\n"); // print text
for(int i=1;i<=n;i++){ // to print the hex values
int val=text[i-1] ;
printf(" %02x",val);
if(i%10==0)
printf("\n");

}


int key=0;
int count=0;
// get the bits
  
printf("\nenter 4-bit key: ");
while(c!='\n'){
c=getchar();
int temp1,temp2;
if(c == '1'){ // if bit is 1
temp1=temp2=1;
temp1=1<<count; // shift count times right
temp2=1<<(count+4); // shift count+4 times right for the first four bits
}
if(c=='0'){
temp1=temp2=0; // no change to be made in key
}
key= key|temp1|temp2;
count++;
  
}
printf("hex ciphertext:\n");
//process the text
for(int i=1;i<=n;i++){
int val=text[i-1]^key ;
printf(" %02x",val); // print the text
if(i%10==0)
printf("\n"); // if 10 char, go to new line

}
printf("\n");

return 0;
}

----------------------------------------------------------------------------------------------------------------------------------------

enter cleartext: two fat dogs Text entered is: two fat dogs Hex encoding is: 74 77 6f 20 66 61 74 20 64 6f 67 73 enter 4-bit

Thanks

Add a comment
Know the answer?
Add Answer to:
Write a program that implements an elementary bit stream cipher. An elementary level bit stream 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
  • 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];                                                      ...

  • Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user...

    Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user to specify the key and the text to be encrypted. A Caesar cipher is a simple substitution cipher wherein each letter in the message is shifted a certain number of spaces down the alphabet -- this number is called the key. a b c d e f g h i j k l m n o p q r s t u v w...

  • C program (Not C++, or C#) Viginere Cipher 1)Ask the user if we are encrypting or...

    C program (Not C++, or C#) Viginere Cipher 1)Ask the user if we are encrypting or decrypting. 2) Ask the user to enter a sentence to be transformed. 3) Ask the user to enter a sentence that will be used as the encryption or decryption key. 4) The sentences (array of characters) should end with a NULL terminator '\0'. 5) The range of values will be all printable characters on the ASCII chart starting with a SPACE - Value 32,...

  • 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...

  • Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher...

    Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the text. The first number denotes the...

  • Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher uses a doc...

    Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the text. The first number denotes the...

  • 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...

  • . Please write a function that will do the following Decryption of a message encrypted with a substitution cipher given cipher text only without any key Please provide comments on each line of code ou...

    . Please write a function that will do the following Decryption of a message encrypted with a substitution cipher given cipher text only without any key Please provide comments on each line of code outlining what that line is doing. Note: Only the Function is to be written, all user inputs i.e the text to be decrypted will be entered earlier in the program. Code must be written in C and be able to be compiled using GCC If any...

  • c++ LUILIIR Exercise #3: The xOr Cipher Write the fol lowing functions: void integerToBinary(int, int [0):...

    c++ LUILIIR Exercise #3: The xOr Cipher Write the fol lowing functions: void integerToBinary(int, int [0): // Convers an integer number to binary and stores the binary // form in an array. I/ Converts a string to binary by converting the ASCII value of I/ each character into binary. l/ Calculates the xor of two binary numbers. void stringToßinary (string, int Il): void xOr(int, int O. int, int [I, int [l): The ASCII values of the characters 'A, 'B', C,...

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