Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encryption Simple

Status
Not open for further replies.

hisheeraz

Programmer
Mar 24, 2003
28
AU
Hello I am stuck here...i need little help if some one could please...

The problem is I want to enter four digits user input and then encrypt that input in to something different...following is the algorithm that i have to use to encrypt...

Replace each digit by (the sum of that digit plus 7) modulus 10.Then swap the first digit with the
third, and swap the second digit with the fourth.

i have written something like...
Code:
int input = 0;
            int tInput = 0;
            string myString = "";
            char c;

            Console.Write("\n Enter number to encrypt >> ");
            myString = Console.ReadLine();

            for (int i = 0; i < myString.Length; i++)
            {
                tInput = myString[i];
                input = input + int32.Parse(tInput);
                Console.WriteLine(input);
            }

Please help me with solving this problem...this problem is from Deitel and Deitel How to Program C Sharp.

Thank You.
RentedLips

§ Rented Lips §
----------------
Begning To Learn
----------------
 
you need to try and break the problem down into small bits. Do this by making some methods. something like...
Code:
private string SwapSecondDigit(string fourthDigit)
{
  string secondDigit = fourthDigit;
  return secondDigit;
}

also rather than working with a string of numbers try using an array of strings e.g after you get the string with myString = Console.ReadLine( ); you can then go
String[ ] numbers = myString.Split( null );

you now have each digit.. you can now swap these easily. To pass each function a value so they can perform their bit you could..e.g
Code:
// pass fourth digit
numbers[ 3 ] = SwapSecondDigit( string myString[ 3 ].ToString() );
not tested but ... Hope this helps

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top