Google Answers Logo
View Question
 
Q: encripted numbers ( No Answer,   2 Comments )
Question  
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.
Answer  
There is no answer at this time.

Comments  
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

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

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 Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy