Question

In: Computer Science

use C++ Cryptography is the study of hiding information or encrypting information. Cryptographers often use things...

use C++

Cryptography is the study of hiding information or encrypting information. Cryptographers often use things called ciphers to encrypt messages. A cyclic cipher is a common, but relatively insecure method of encrypting a message. It is achieved by replacing every letter in the word or message with another letter in the alphabet a certain number of positions away. For example, if the message to be encrypted (the plaintext) was IBM and the cipher key was -1, the resulting message (the ciphertext) would be HAL. 'I' was replaced by the letter one position to the left of it in the alphabet: 'H', etc.

If the letter happens to be 'Y' and the key is 3, the cipher "wraps around" to the beginning of the alphabet and the encrypted letter would be 'B'.

Write a program to "encrypt" one character using a cyclic cipher. You may assume that the character is an alphabetic letter, but it may be given in lowercase or uppercase. The key to the encoding will be the number of characters to move "up" in the alphabet (toward Z); negative numbers move "down" in the alphabet (toward A). You may assume that the key will be greater than -26 and less than 26 (so we will never cycle the whole way through the alphabet). Output the encrypted character as a capital letter.

Your program should run like the examples shown below.

This program encrypts a single letter.

Letter: a
Key: 1

Result: B
This program encrypts a single letter.

Letter: a
Key: -1

Result: Z
This program encrypts a single letter.

Letter: f
Key: 4

Result: J
This program encrypts a single letter.

Letter: M
Key: 6

Result: S

Solutions

Expert Solution

C++ Code:

#include <iostream>

using namespace std;

int main()
{
char letter,result;
int key;
cout<<"This program encrypts a single letter.\n\nLetter: ";
cin>>letter;
cout<<"Key: ";
cin>>key;
if(key>0)
{
if(letter>=97&&result<=122)
{
result=(letter+key-97)%26+97;
}
else
{
result=(letter+key-65)%26+65;
}
}
else
{
key=key*(-1);
if(letter>=97&&result<=122)
{
result=(letter+(26-key)-97)%26+97;
}
else
{
result=(letter+(26-key)-65)%26+65;
}

}
if(result>=97&&result<=122)
{
result=result-32;
}
cout<<"\nResult: "<<result;
return 0;
}

Code Screenshot:

Output Screenshot:

1

2

3

4


Related Solutions

Cryptography*** Let’s assume you do DES double encryption by encrypting a plaintext twice with K1 and...
Cryptography*** Let’s assume you do DES double encryption by encrypting a plaintext twice with K1 and K2 respectively. Is this method more secure than the regular single DES encryption? Please explain your reason.
Report on hiding information and watermarks in Data security technologies?.
Report on hiding information and watermarks in Data security technologies?.
Write a C program A simple method for encrypting data is that of ROT 13. The...
Write a C program A simple method for encrypting data is that of ROT 13. The method takes each latin letter of plain text and moves it to the next letter 13 times in latin alphabet (wrapping around if necessary). For those of you who are unaware the latin alphabet is the following a b c d e f g h i j k l m n o p q r s t u v w x y z This...
how can we use cryptography libraries in Python
how can we use cryptography libraries in Python
Psychological research shows that people often 'remember' things that never happened. Given this information, describe practices...
Psychological research shows that people often 'remember' things that never happened. Given this information, describe practices or policies for police interrogations, eyewitness testimony or psychotherapy that would prevent the creation of false memories.
Widespread use of cryptography can mean trouble for law enforcement and security personnel when crooks and spies use cryptography to secure their communications from wiretapping.
Widespread use of cryptography can mean trouble for law enforcement and security personnel when crooks and spies use cryptography to secure their communications from wiretapping. Under U.S. law, communications utilities are required to provide law enforcement access to communication links when proper judicial process has been observed. Such access is useless if the messages they provide access to are encrypted with powerful security. For years the U.S. and other countries have tried to control the spread of cryptographic technologies, with...
Steganography is the technique of hiding secret messages/information within other non-secret data/information. One popular way of...
Steganography is the technique of hiding secret messages/information within other non-secret data/information. One popular way of steganography is hiding text (plaintext) within images (cover text). Each image is a collection of pixels, where each pixel is typically represented by 3 values (RGB). Each of R, G, and B is a value between 0 and 255 and thus can be represented by 8 bits. The color of the pixel depends on these values. However, if the least significant bit (last bit...
Encrypting Text with a Caesar Cipher Write a C program caesar.c which reads characters from its...
Encrypting Text with a Caesar Cipher Write a C program caesar.c which reads characters from its input and writes the characters to its output encrypted with a Caesar cipher. A Caesar cipher shifts each letter a certain number of positions in the alphabet. The number of positions to shift will be given to your program as a command line argument. Characters other than letters should not be encrypted. Your program should stop only at the end of input. Your program...
Required information Use the following information for the Quick Study below. [The following information applies to...
Required information Use the following information for the Quick Study below. [The following information applies to the questions displayed below.] BatCo makes metal baseball bats. Each bat requires 2.00 kg of aluminum at $20 per kg and 0.20 direct labor hours at $18 per hour. Overhead is assigned at the rate of $40 per direct labor hour. QS 23-5 Standard cost card LO C1 What amounts would appear on a standard cost card for BatCo?    Required information Use the...
The null hypothesis is often referred to as the status quo as it represents how things...
The null hypothesis is often referred to as the status quo as it represents how things have been or are typically expected to be. The alternate hypothesis is what we believe has changed. Why should the alternate hypothesis be the exact opposite of the null hypothesis?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT