Ask Experts Questions for FREE Help !
Ask
    peter1988's Avatar
    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's Avatar
    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's Avatar
    shihouzhuge Posts: 131, Reputation: 6
    Junior Member
     
    #3

    Oct 6, 2009, 09:49 AM
    Quote Originally Posted by peter1988 View Post
    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[4];// input the number,it is char
    cin>>a;
    int b[4];
    b[0]=(int(a[2])-int('0')+7)%10;// change the char to int;
    b[1]=(int(a[3])-int('0')+7)%10;
    b[2]=(int(a[0])-int('0')+7)%10;
    b[3]=(int(a[1])-int('0')+7)%10;
    cout<<"Encrypted number is:";
    for(int I=0;i<4;i++){ //output the answer
    cout<<b[i];
    }
    }
    shihouzhuge's Avatar
    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's Avatar
    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? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


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.


View more questions Search