C# Console Application for ROT13 (encryption)

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 3495 Views - Last Post: 02 December 2012 - 11:02 AM Rate Topic: -----

#16 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,537
  • Joined: 08-April 09

Re: C# Console Application for ROT13 (encryption)

Posted 01 December 2012 - 10:34 AM

rideronix, just do what tlhIn`toq told you to do in post #11
string someArgs = "Yogi Bear"; // a string is a char[]

foreach (char letter in someArgs)
{
    // do something with the letter(witch is now of type char but you need an int
}


see how foreach works

Or you could use the ToCharArray(), like
//Now the array contains every char in the value string
char[] array = value.ToCharArray();

This post has been edited by Michael26: 01 December 2012 - 10:39 AM

Was This Post Helpful? 0
  • +
  • -

#17 rideronix  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 24-November 12

Re: C# Console Application for ROT13 (encryption)

Posted 02 December 2012 - 03:01 AM

I'm trying but only with this:

        static void Main(string[] args)
        {
            foreach (char letter in args[])
           {
           }
        }


I get the "args[]" underlined saying: "Value expected" and if I remove the "[]" it underlines foreach and says can't convert type string to char.
Was This Post Helpful? 0
  • +
  • -

#18 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,537
  • Joined: 08-April 09

Re: C# Console Application for ROT13 (encryption)

Posted 02 December 2012 - 04:44 AM

I did a bit of research and found this.
Check it out.
Was This Post Helpful? 0
  • +
  • -

#19 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,612
  • Joined: 23-August 08

Re: C# Console Application for ROT13 (encryption)

Posted 02 December 2012 - 05:23 AM

View Postrideronix, on 02 December 2012 - 05:01 AM, said:

I'm trying but only with this:

        static void Main(string[] args)
        {
            foreach (char letter in args[])
           {
           }
        }


I get the "args[]" underlined saying: "Value expected" and if I remove the "[]" it underlines foreach and says can't convert type string to char.


For the love of Pete, listen to what you're being told so you actually LEARN something!

string[] args


args is an array of string. As you've been told repeatedly.

Each of those strings in the array is an array of chars. So FIRST you need to go through each element of the array of strings to get the word, and once you have the word (the string) you can go through THAT array char by char.
Was This Post Helpful? 0
  • +
  • -

#20 rideronix  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 24-November 12

Re: C# Console Application for ROT13 (encryption)

Posted 02 December 2012 - 08:01 AM

Thank you that was clear !

I got the conversion right but when I try to unconvert.

Convert:


        static void Main(string[] args)
        {
            foreach (string letter in args)
            {
                for ( int n = 0; n < args.Length; n++)
                {
                    char lettre = letter[n];
                    Convert.ToInt32(lettre);
                    int rot13 = (int)lettre;




Unconvert:

                rot13 = (char)lettre;
                letter[n] = lettre; // Error here, I guess you can't modify an array like this... Do I need make a new array ?



How can I convert backwise ?

This post has been edited by rideronix: 02 December 2012 - 08:02 AM

Was This Post Helpful? 0
  • +
  • -

#21 rideronix  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 24-November 12

Re: C# Console Application for ROT13 (encryption)

Posted 02 December 2012 - 08:42 AM

Problem solved.


                lettre = (char)rot13;
                Console.Write(lettre);



Works perfectly. However it display each new string one under another, how can I manage not to do this ? I wrote "Console.Write()" and not "Console.WriteLine()" but doesn't seem to change anything...
Was This Post Helpful? 0
  • +
  • -

#22 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3652
  • View blog
  • Posts: 11,421
  • Joined: 05-May 12

Re: C# Console Application for ROT13 (encryption)

Posted 02 December 2012 - 08:45 AM

Recompile again. Be sure you are running the code with the Console.Write() keeps everything on the same line.
Was This Post Helpful? 1
  • +
  • -

#23 rideronix  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 24-November 12

Re: C# Console Application for ROT13 (encryption)

Posted 02 December 2012 - 11:02 AM

Thanks all done. Now I've ran into another problem but I'll make a new post since it's not really related.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2