Skip to content

Instantly share code, notes, and snippets.

@janell-baxter
Last active October 9, 2018 17:19
Show Gist options
  • Save janell-baxter/650c9e7b50fe760ef7d07f9b80b407e7 to your computer and use it in GitHub Desktop.
Save janell-baxter/650c9e7b50fe760ef7d07f9b80b407e7 to your computer and use it in GitHub Desktop.
Example framework for string manipulation example (simple substitution cipher). Introduction to Programming, Summer 2018
using System.Linq;
namespace Cipher
{
class Cipher
{
string alphabet;
string substitute;
public Cipher()
{
alphabet = "abcdefghijklmnopqrstuvwxyz";
substitute = "opdefghiqrsxyzabcjklmntuvw";
}
public string Encrypt(string _message)
{
int index;
char replacement = 'z';
string result = "";
_message = _message.ToLower();
foreach (char c in _message)
{
//add code here to replace each character c
//with the letter from the same index number in the substitute string
}
return result;
}
public string Decrypt(string _message)
{
string result = "";
return result;
}
}
}
using static System.Console;
namespace Cipher
{
class Message
{
public Message()
{
WriteLine("Hello agent.");
Run();
}
private void Run()
{
Cipher cipher = new Cipher();
string message;
Clear();
Write("Enter text: ");
message = ReadLine();
WriteLine(cipher.Encrypt(message));
WriteLine("Press any key to continue...");
ReadKey();
Run();
}
}
}
using System;
namespace Cipher
{
class Program
{
static void Main()
{
Console.Title = "Manipulating String Example: Simple Cipher";
Message message = new Message();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment