jmkotman
asked on
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.Cryptograp hy;
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()
{
}
}
}
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.Cryptograp
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()
{
}
}
}
ASKER
Is there a built in class which knows all the character?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
for (int i = 0; i < inputString.length; i ++)
{
int encodedChar = ((int)inputString[i] + charsToShift);
outputString += (char)encodedChar;
}