2001-Singapore Problem 1 Encryption

xiaoxiao2021-03-06  62

Problem 1

ENCRYPTION

Input File: data1.txt

Say you are the founder and sole employee of your own e-business start-up. Hours before delivering an e-commerce solution to your very first client, you realize to your horror that you have forgotten to include encryption features for sensitive information.

Faced with a very tight deadline, you decide to incorporate a simple encryption routine and later sell a security upgrade to your client at a tidy sum. After looking through possible methods that you can implement quickly, you finally settle on the following scheme known as a ViGenere Cipher.

First, you determine a small repeated key that is the length of your plaintext (unencrypted) message. Next, you align the plaintext message such that the first letter of the message is aligned to the first letter of the key. Finally, each key letter index is added to its corresponding plaintext letter index to produce the ciphertext (encrypted) letter index. These combined ciphertext letter indices will form the final encrypted message. Your task is to write such a program.

INPUT

The input file consists of pairs of lines. The first line of each pair will contain the key while the second line will contain the plaintext message. Only letters of the alphabet (AZ) plus a space will be used. These may be in upper- Or Lower-Case and You Will Have to Convert The INTO UPPER-CASE IF Necessary.

OUTPUT

................. ..

Sample Input

Abcabcabcabcab

Attack At Dawn

SHINESHINES

How are you

Sample Output

BvwbenacwafDXP

Awfnfkmimtn

// author iplinger // IDE VC 6.0pragma HDRSTOP # include # include # include using namespace std; char key [1000]; char message [1000]; char result [1000]; String key_string; // The purpose is to caculate the length of key-array.

// encryptvoid encrypt () {key_string = key; int Temp1; int Temp2; char TEMP3; for (int i = 0; i 26? 64-26: 64; cout << temp3;}}

// Read file void readfile () {ifstream Openfile ("/ mnt / hgfs / acm / solution / 2001-singapore / data1.txt"); // Open file, You Should Apply The Path and Name of the File That You Want to open in Linux; while (! OpenFile.eof ()) // EOF () function is used to determine the end of the file, specifying # for the end of INPUT {OpenFile.getLine (KEY, 1000); OpenFile.Getline (Message, 1000; strupr (key); strupr (message); // method strupr () Converts a string to uppercase. Encrypt (); cout << endl;} OpenFile.close (); // Turn off file resources}

Void main () {readfile (); // char A; // cin >> a;

转载请注明原文地址:https://www.9cbs.com/read-111973.html

New Post(0)