Created
September 26, 2018 16:56
-
-
Save josephhanson/faf8b6b403d9cde0895de181265030e3 to your computer and use it in GitHub Desktop.
HTDS: Wrapping at End of Fixed Character String
This file contains 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
using System; | |
using System.Text; | |
namespace CesarCipher { | |
class Program { | |
static void Main(string[] args) { | |
// if upper or lower letter increment by N (rotate at end of alphabet) | |
// 97 - 122 lower, 65 - 90 upper | |
// % 26 allows us to work with #'s greater than 26 with same algorithm | |
var offset = 2 % 26; | |
var input = "Yes"; | |
var output = new StringBuilder(); | |
foreach (var character in input) { | |
if (char.IsLower(character)) { | |
output.Append((char)(97 + ((character - 97) + offset) % 26)); | |
} else if (char.IsUpper(character)) { | |
output.Append((char)(65 + ((character - 65) + offset) % 26)); | |
} else { | |
output.Append(character); | |
} | |
} | |
Console.WriteLine(output); // Agu | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment