Question

1) Echo the input: First, you should make sure you can write a program and have...

1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the CS dept Linux network] 2) Simple Substitution Cipher: One of the earliest and simplest types of ciphers was called a "simple substitution cipher". And one of the simplest of these simple substitution ciphers was the cipher where each letter is replaced by the next letter in the alphabet. For example, 'a' is replaced by 'b', 'b' is replaced by 'c', and so on, until you get to 'z', which is replaced by 'a'. Have your program take a single word as input and perform this simple substitution cipher on it, then print out the encrypted text (also known as ciphertext) [2 points] Hint: you can add a numerical value to a character. For example, if you add 1 to the character 'a', it becomes 'b'. If you add 2 to 'a', it becomes 'c', and so on and so forth. Be careful with 'z' - it needs a special case. 3) Polyalphabetic (or Block) Cipher: Simple (or monoalphabetic) substitution ciphers can be easily broken by letter frequency analysis, leading to the development of polyalphabetic ciphers, which are the precursors to block ciphers, which are the basis for modern cryptography. You'll implement a simple block cipher that will work as follows: instead of simply "increasing" each letter by 1, imagine the plaintext being divided into blocks of 8 characters. Then, in each block, you'll increase the first letter by 1, the second letter by 2, the third letter by 3, until you reach the 8th letter, which you'll increase by 8. The 9th letter of the plaintext will start the 2nd block, thus the 9th letter will be increased by 1 again, the 10th letter by 2, and so on and so forth. Example: plaintext: c r y p t o g r a p h y you add: 1 2 3 4 5 6 7 8 1 2 3 4 ciphertext: d t b t y u n z b r k c [4 points for getting this to work in all cases. 2 points for getting this to work for characters that don't don't go past 'z'.] Hint: to get this to "wrap around" from 'z' to 'a', it will require more than just a special case. You must figure out and implement a general rule for what to do when the result of your substitution causes the value of your character to exceed 'z'. Being able to treat characters as their integer values in mathematical expressions may help you here - for example, you can compare characters with < and > (less than and greater than). You can compare 2 characters or you can compare a character's ASCII value to an integer. If you're really stuck, you may want to look at an ASCII chart. Extra Credit: You may complete any (or all) of these you're able to, after completing step 3. [1 extra point for completing at least one of these] 4) Variable-Length Block Cipher with Key: For this step, you'll need the user to enter a key. This key will be a word (no spaces) consisting of only lowercase letters. Then, you'll implement a block cipher as in step 3, except the length of the key will be the size of the block, and you'll add the alphabetic position of each letter in the key to each letter in the block. [1 point] For example, if your key is "crypto", you'll add: 3 to the first letter of the plaintext (c=3) 18 to the 2nd letter of the plaintext (r=18) 25 to the 3rd letter of the plaintext (y=25) 16 to the 4th letter of the plaintext (p=16) 20 to the 5th letter of the plaintext (t=20) 15 to the 6th letter of the plaintext (o=15) 3 to the 7th letter of the plaintext, because we're back to the "c" at the beginning of "crypto". 5) Allow the Plaintext to be a Sentence: Treat spaces as the 27th letter of the alphabet, so that your plaintext can be a sentence (or even a paragraph without punctuation). Encrypt spaces as you would any other character, but note that the "space" character will need to be treated as a special case, since it is not next to the lowercase letters in ASCII. Note that this will require altering your code from steps 2, 3, and 4 if you did it. [1 point] Hint: cin by itself will only read a string until the first space. To read in a sentence, use getline(cin,stringname); 6) Use Command Line Arguments: Allow the user to enter the input (the plaintext, and the key if applicable) through his choice of a command line argument or being prompted for input. The way that this will work is that if the user enters a command line argument, that will be used as the input. If he does not, he will be asked to input his plaintext (and key if applicable) as normal. An example of using command line arguments is included in my "readings and code samples" on Blackboard. [1 point to get it working on an input of a one-word plaintext (and key if applicable), 2 points to get it working on a sentence of plaintext] Note that having a sentence as your plaintext in a command line argument will require using techniques a fair bit beyond the scope of this course, so you can use a command line argument for just a one-word plaintext while allowing a sentence of plaintext to be entered via prompting the user.

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

Echo the input: First, you should make sure you can write a program and have it compile and run,
take input and give output. So to start you should just echo the input.
This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:".

int main()
{
char ch[30];
printf("Enter your text");
scanf("%s",ch);
printf("this is the plaintext you entered: %s",ch);
return 0;
}

2) Simple Substitution Cipher:

int main()
{
char ch[30];
char ch2[30];
printf("Enter your text");
scanf("%s",ch);
printf("this is the plaintext you entered: %s",ch);
int z;

for (i = 0; ch[i] != '\0'; i++) {
     z=ch[i];
z=z+1;
ch2[i]=(char) z;
}
printf("Your new Cipher word is : %s"+ ch2);

}

3) Polyalphabetic (or Block) Cipher

int main()
{
char ch[30];
char ch2[30];
printf("Enter your text");
scanf("%s",ch);
printf("this is the plaintext you entered: %s",ch);
int z;
int count=1;

for (i = 0; ch[i] != '\0'; i++) {
if(i%9==0)
count =1;
count=count+i;
z=z+count;  // Increment z by j here
ch2[i]=(char) z;
}
}
4) Variable-Length Block Cipher with Key

int main()
{
char ch[30];
char ch2[30];
char key[30];
printf("Enter your text");
scanf("%s",ch);
printf("Enter your key");
scanf("%s",key);
printf("this is the plaintext you entered: %s",ch);
int z;
int count;
int keyLength=0;

for (int i = 0; key[i] != '\0'; i++)
  keyLength=keyLength+1;

for (int i = 0; ch[i] != '\0'; i++) {
z=ch[i];
j=i;
if(i%(keyLength+1)==0)
{
  j=i%(keyLength+1);
}
count=findKeyNumber(key[j]);
z=z+count;
ch2[i]=(char) z;
  j=j+1;
}
}

int findKeyNumber(char ch)
{
int count;
if(ch=='a')
  count=1;
else if (ch=='b')
  count =2;
  
  //do it so on till z;
  
  return count;

}

Add a comment
Know the answer?
Add Answer to:
1) Echo the input: First, you should make sure you can write a program and have...
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
  • 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...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

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

  • Write a Python program which implements the following two classical cryptosystem which we covered n class:...

    Write a Python program which implements the following two classical cryptosystem which we covered n class: a) Affine Cipher b) Vigenere Cipher Your program should consist of at least five functions: a) Two functions named encrypt, one for each of the two algorithms which accepts a lowercase alphabetical plaintext string and key as input and outputs a corresponding cipher text string. b) Two functions named decrypt, one for each of the two algorithms which accepts a lowercase alphabetical ciphertext string...

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

  • a. Ask the user for the input of a letter (char type). Write a function that...

    a. Ask the user for the input of a letter (char type). Write a function that takes a char as the argument (parameter) and returns the ASCII value of that char back to the caller. Call the function using the char variable and taking input from the user (no validation required). Display the value in ASCII. b. Write a program that takes a char as the argument (parameter) and uses a loop to interrogate the char, calling a function that...

  • Write a javascript program which implements the following two classical cryptosystem which we covered in class:...

    Write a javascript program which implements the following two classical cryptosystem which we covered in class: Affine Cipher Vigenere Cipher Your program should consist of at least five functions: Two functions named encrypt, one for each of the two algorithms which accepts a lowercase alphabetical plaintext string and key as input and outputs a corresponding cipher text string. Two functions named decrypt, one for each of the two algorithms which accepts a lowercase alphabetical ciphertext string and a key as...

  • In C programming please (b) You will write a program that will do the following: prompt...

    In C programming please (b) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter 'O' You will compule statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character 'Q' Example input mJ0*5/1+x1@3qcxQ The 'Q' should be included when computing the statistics properties of the input....

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

  • 14.3: More Sentences Write a program that allows a user to enter a sentence and then...

    14.3: More Sentences Write a program that allows a user to enter a sentence and then the position of two characters in the sentence. The program should then report whether the two characters are identical or different. When the two characters are identical, the program should display the message: <char> and <char> are identical! Note that <char> should be replaced with the characters from the String. See example output below for more information. When the two characters are different, the...

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