Skip to content

Instantly share code, notes, and snippets.

@Naphier
Created December 30, 2015 17:51
Show Gist options
  • Save Naphier/74c3ac6c8027162eb640 to your computer and use it in GitHub Desktop.
Save Naphier/74c3ac6c8027162eb640 to your computer and use it in GitHub Desktop.
Strategy Pattern Example - String Output - EncryptedOutput
public class EncryptedOutput : IOutputStrategy
{
public string Output(string input)
{
char[] array = input.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
int number = (int)array[i];
if (number >= 'a' && number <= 'z')
{
if (number > 'm')
{
number -= 13;
}
else
{
number += 13;
}
}
else if (number >= 'A' && number <= 'Z')
{
if (number > 'M')
{
number -= 13;
}
else
{
number += 13;
}
}
array[i] = (char)number;
}
return new string(array);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment