Encryption Program using Caesar shift C#

I am writing a program which reads in information from the file below: The program uses "Cryptography" and "Caesar Shift" to encode or decode the string.

e,COMPUTER SCIENCE,1
e,HELLO WORLD,11
e,THIS IS JUST A TEST,8
d,FDPNQVUFS!TDJFOD,1
d,KZZKXYIGVOZGR&R,6
d,TSHTXLT%GW,5

The first letter "e" or "d" tells the program if the string is going to be encoded or decoded.  The next string is the string that is going to be encoded or decoded.  The next integer tell the program how many steps the shift the word to be encoded or decoded.  So to decode a message, each letter is shifted N letters to the left and to encode a message, each letter is shifted N letters to the right depending on what the last number is.  So COMPUTER SCIENCE should output FDPNQVUFS!TDJFOD

I have writing everything to read in the file here is that i have so far:
So after the file is read in, somehow i need to beable to shift the string and change the letters.


using System;
using System.IO;
using System.Security.Cryptography;

namespace Lab07_Encryption
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
      {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main(string[] args)
            {
                  ReadFile();
            }

            public static void ReadFile()
            {

                  StreamReader fileReader;
                  string fileName = "input.txt";
             
                  fileReader = new StreamReader(fileName);
                  string sLine;
      
                  sLine = fileReader.ReadLine();

                  string [] split;
                  const char delm = ',';

                  while(sLine != null)
                  {
                        split = sLine.Split(delm);

                        string encryption = split[0];
                        string message = split[1];
                        int shift = int.Parse(split[2]);

                        string en = "e";

                        if(encryption == en)
                        {
                              encode();
                        }
                        else
                        {
                              decode();
                        }

                        sLine = fileReader.ReadLine();
                  }
            }

            public static void encode()
            {
      
            }

            public static void decode()
            {
            
            }
      }
}
jmkotmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AngryBinaryCommented:
This looks like a homework assingment, so I'll just give you the general idea. You will want to convert the string to an array of characters, which can be cast as integers and operated upon as such:

for (int i = 0; i < inputString.length; i ++)
{
    int encodedChar = ((int)inputString[i] + charsToShift);
    outputString += (char)encodedChar;
}
0
jmkotmanAuthor Commented:
Is there a built in class which knows all the character?
0
AngryBinaryCommented:
The upshot is, there's no need to know the integer values of the characters ahead of time. A 'char' variable contains an integer, which represents (in .NET) it's Unicode value. Adding a number 'n' to that value will give you the Unicode value of another character n positions from the original character. As you cast from int to char and vice-versa, the conversion occurs automatically. In fact, underneath, they are both the same intrinsic type. To illustrate,

char myChar = 'a'; //------------------myChar contains the character code 65, or lowercase 'a'.
int myCharCode = (int)letter; //------myCharCode contains the integer 65

myCharCode += 2; //-----------------myCharCode now contains the integer 67
myChar = (char)myCharCode; //----myChar now contains the character code 67, or lowercase 'c'.

So, to answer your question, I suppose you can say that char 'knows' all the characters, although it's really just a matter of semantics.

--Randall
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.