CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: encryption

  1. #1
    Join Date
    Jun 2009
    Posts
    16

    encryption

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace CMH_ENCRYPT
    {
        class Program
        {
            static void Main(string[] args)
            {
                string Name,Value;                  //declaration of variable
                int Output;
                int Formula;
    
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("\n\n\t\t\t\t"+"ENTER NAME:");               //INPUTING VARIABLE Name
                Name = Console.ReadLine();
                
            
    
                Console.Write("\n\n\t\t\t      "+"ENTER VALUE (1-10): ");     //NUMBER THAT WILL ADD TO 9%10
                Value = Console.ReadLine();
    
    
                Formula =(Convert.ToInt32(Value)+ 9) % 10;  //FORMULA IN GETTING THE ENCRYPTION
                                                            
    
               
                for (int i = 0; i < Name.Length; i++)       //WILL TRAVERSE THE ENTIRE CHAR
                {
                     Convert.ToInt32(Name[i]);              //WILL CONVERT NAME TO INT
                     Output = Formula + Name[i];            //ENTERING THE SUM OF FORMULA AND NAME TO LOCAL VARIABLE OUTPUT
    
                     Console.Write("the encryption is: " + "{0}",Convert.ToChar(Output));   //DISPLAY THE OUTPUT
    
    
                }
                Console.Read();
    
                    
                
    
               
    
            }
        }
    }

    this program is already ok but i want to include spacing .

    how to do that. .
    Last edited by Shuja Ali; July 3rd, 2009 at 01:43 PM. Reason: Added Code Tags

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: encryption

    What does include spacing mean? Do you want spaces to be encrypted too or do you want to add a space between first and last name in the encrypted output?

    Please be more specific as to what you want.

  3. #3
    Join Date
    Jun 2009
    Posts
    16

    Re: encryption

    oh . .sori sir. .

    example:
    Please enter name: A B C
    ENTER VALUE(1-10) : 1

    (should be)OUTPUT: A B C

    but there if you enter A B C the output will be A!B!C something like that. .

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: encryption

    You said the program is working ok. But I don't think so. the statement Convert.ToInt32(Name[i]); //WILL CONVERT NAME TO INT is not being assigned to any variable. And when I run the program I am getting the same input back.

    If you are trying to do encryption / decryption, you should be using the in built functionality of .NET Framework. Take a look at System.Security.Cryptography documentation on msdn.

    In case you still want your program to work, here is something that I did with your code.
    Code:
      string Name, Value;                  //declaration of variable
                int Output;
                int Formula;
    
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("\n\n\t\t\t\t" + "ENTER NAME:");               //INPUTING VARIABLE Name
                Name = Console.ReadLine();
                Console.Write("\n\n\t\t\t      " + "ENTER VALUE (1-10): ");     //NUMBER THAT WILL ADD TO 9&#37;10
                Value = Console.ReadLine();
                Formula = (Convert.ToInt32(Value) + 9) % 10;  //FORMULA IN GETTING THE ENCRYPTION
                string encryptedString = string.Empty;
                //encrypt the data using the key entered by the user
                for (int i = 0; i < Name.Length; i++)       //WILL TRAVERSE THE ENTIRE CHAR
                {
                    int key = Convert.ToInt32(Name[i]);              //WILL CONVERT NAME TO INT
                    Output = Formula + key;            //ENTERING THE SUM OF FORMULA AND NAME TO LOCAL VARIABLE OUTPUT
                    encryptedString += Output.ToString();
                }
                Console.Write("the encrypted output is: " + "{0}", encryptedString);   //DISPLAY THE OUTPUT
                Console.Read();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured