Created
December 30, 2015 17:51
-
-
Save Naphier/74c3ac6c8027162eb640 to your computer and use it in GitHub Desktop.
Strategy Pattern Example - String Output - EncryptedOutput
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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