 Ask Remember Me? peter1988 Posts: 12, Reputation: 1 New Member #1 Jan 13, 2009, 08:26 PM
Something about programming!
Can anyone help me about this question>>>?? (Microsoft Visual C++)

A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four-digit integers. They have asked you to write a program that will encrypt their data so that it may be transmitted more securely. Your program should read a four-digit integer and encrypt it as follows: Replace each digit by the remainder after the sum of that digit plus 7 is divided by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. (7 marks)

Sample output:

Enter a four-digit number to be encrypted: 5678
Encrypted number is 4523 simonjarvis Posts: 2, Reputation: 2 New Member #2 May 1, 2009, 10:13 PM
// Crude answer not very good as relies on transmitting
// only 4 digit integers but can be up to 32767 and cryptography is no good
// very easily broken but this is more of a simple exam question I guess as in
// real life this is not a practicle solution. You would want to encrypt the connection via
// SSH, CRYPTO RPC or Encrypted Winsock not the actual data unless it is a concern
// with capturing data on the internal network.

#define REV(x)((x + 3<10)?(x + 3):(x+3-10))
#define DECRYPTHOUSANDS(x)(REV((x / 1000)))
#define DECRYPHUNDREDS(x)(REV((x % 1000) / 100))
#define DECRYPTENS(x)(REV(((x % 1000) % 100) / 10))
#define DECRYPONES(x)(REV(((x % 1000) % 10)))
#define CRYPTHOUSANDS(x)( ((x / 1000) +7 ) % 10 )
#define CRYPHUNDREDS(x)( (((x % 1000) / 100) +7 ) % 10 )
#define CRYPTENS(x)( ((((x % 1000) % 100) / 10) +7 ) % 10 )
#define CRYPONES(x)( ((((x % 1000) % 100) % 10) +7 ) % 10 )
#define SWAP(v,x,y,z)( (v * 10) + ( x ) + ( y * 1000 ) + ( z * 100 ) )

int Cryp(int _val)
{
int _thousand(CRYPTHOUSANDS(_val));
int _hundred(CRYPHUNDREDS(_val));
int _tens(CRYPTENS(_val));
int _ones(CRYPONES(_val));
return SWAP (_thousand,_hundred,_tens,_ones);;
}
int DeCryp(int _val)

{
int _thousand(DECRYPTHOUSANDS(_val));
int _hundred(DECRYPHUNDREDS(_val));
int _tens(DECRYPTENS(_val));
int _ones(DECRYPONES(_val));
return SWAP (_thousand,_hundred,_tens,_ones);

} shihouzhuge Posts: 131, Reputation: 6 Junior Member #3 Oct 6, 2009, 09:49 AM Originally Posted by peter1988 Can anyone help me about this question>>>???(Microsoft Visual C++)

A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four-digit integers. They have asked you to write a program that will encrypt their data so that it may be transmitted more securely. Your program should read a four-digit integer and encrypt it as follows: Replace each digit by the remainder after the sum of that digit plus 7 is divided by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. (7 marks)

Sample output:

Enter a four-digit number to be encrypted: 5678
Encrypted number is 4523

#include<iostream.h>
void main()
{
cout<<"Enter a four-digit number to be encrypted:";
char a;// input the number,it is char
cin>>a;
int b;
b=(int(a)-int('0')+7)%10;// change the char to int;
b=(int(a)-int('0')+7)%10;
b=(int(a)-int('0')+7)%10;
b=(int(a)-int('0')+7)%10;
cout<<"Encrypted number is:";
for(int I=0;i<4;i++){ //output the answer
cout<<b[i];
}
} shihouzhuge Posts: 131, Reputation: 6 Junior Member #4 Oct 6, 2009, 09:51 AM
I used Microsoft visual c++6.0,and the answer is compiled without faults.
Good luck! Dalia_2011 Posts: 1, Reputation: 1 New Member #5 Dec 29, 2010, 08:55 AM
I want answer this question in java
Q1. A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data is transmitted as four-digit integers. They have asked you to write a program that will encrypt their data so that it may be transmitted more securely.
Your program should read a four-digit integer and encrypt it as follows: Replace each digit by (the sum of that digit plus 7) modulus 10. Then, swap the first digit with the third and the second with the fourth. Then print the encrypted integer.
Write a program that inputs four-digit integer and prints an encrypted integer number and decrypts it to form the original number. (Use a method to decrypt and another to encrypt)

Not your question?

 Question Tools Search this Question Show Printable Version Email this Page Search this Question: Advanced Search

## Check out some similar questions!

C programming [ 2 Answers ]

I'll be extremely thankful if u could provide me with a c program that convert a given nfa to dfa

C programming [ 4 Answers ]

Write and test a function hydroxide that takes a chemical formula as a parameter and returns True if the chemical is a hydroxide (i.e. ends in OH) and returns False otherwise. Example: Enter a chemical formula: NaOH NaOH is a hydroxide. Enter a chemical formula: H2O H2O is not a...

Programming a t.v. [ 1 Answers ]

I bought a vizio t.v. and was wondering if anyone could tell me how to programming a direct t.v. remote to the television because it's not listed on the programs:confused:

Qt programming [ 1 Answers ]

Hi, My name is anshahmed.I am doing final year B.TECH.Now I am doing a project and I want to use qt programming .Whie I was compiling the qt programm the compiler giving errors in header file(qpplicaton.h) .how can I compile the qt programm.