![]() |
|
|
| Subject:
encripted numbers
Category: Computers > Programming Asked by: coriander-ga List Price: $5.00 |
Posted:
02 Jun 2005 13:42 PDT
Expires: 02 Jul 2005 13:42 PDT Question ID: 528661 |
I need a program that can 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, swap the second digit with the fourth and print the encrypted integer. Write a separate program that inputs an encrypted four-digit integer and decrypts it to form the original number. |
|
| There is no answer at this time. |
|
| Subject:
Re: encripted numbers
From: manuka-ga on 02 Jun 2005 18:39 PDT |
Does this need to be in some particular language? |
| Subject:
Re: encripted numbers
From: j3f-ga on 02 Jun 2005 22:24 PDT |
c++ code:
encrypt code:
#include <iostream>
#include <string>
int main()
{
//get input
string encrypt_me;
cin >> encrypt_me;
//add 7 mod 10
int i,j;
for (i=0,i<4,i++)
{
j = encrypt_me[i] - '0';
j += 7;
j %= 10;
encrypt_me[i] = '0' + j;
}
//reorder number
encrypt_me[0] &= encrypt_me[2];
encrypt_me[1] &= encrypt_me[3];
//print out result
cout << encrypt_me;
return 0;
}
decrypt code:
#include <iostream>
#include <string>
int main()
{
//get input
string decrypt_me;
cin >> decrypt_me;
//reorder number
decrypt_me[0] &= decrypt_me[2];
decrypt_me[1] &= decrypt_me[3];
//undo 7 mod 10
int i,j;
for (i=0,i<4,i++)
{
j = decrypt_me[i] - '0';
j += 3;
j %= 10;
encrypt_me[i] = '0' + j;
}
//print out result
cout << decrypt_me;
return 0;
}
--jeff |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |