[C#] Offset Encryption
I got bored in my IT Class one day and wrote this up. Figured I'd share. The only thing I can think of to add is the, if a letter is capitalized, it returns capitalized. Other then that, numbers work too!
Forgot! The isNumeric Function.
public static String Offset(String toEncrypt, Int32 offsetValue)
{
String alphabet = "abcdefghijklmnopqrstuvwxyz";
String newEncryption = String.Empty;
foreach (Char character in toEncrypt)
{
if (isNumeric(character.ToString()) == false)
{
Int32 curPosition = 0;
for (int i = 0; i < alphabet.Length; i++)
{
if (alphabet[i] == character)
{
curPosition = i;
break;
}
}
Int32 newPosition = curPosition + offsetValue;
if (newPosition >= alphabet.Length)
newPosition = (curPosition + offsetValue) - alphabet.Length;
newEncryption += alphabet[newposition];
}
else
{
newEncryption += Int32.Parse(character.ToString()) + offsetValue;
}
}
return newEncryption;
}
[/newposition][/i]Forgot! The isNumeric Function.
public static Boolean isNumeric(String Value)
{
double num;
bool isNum = double.TryParse(Value, out num);
return true != false ? isNum : true;
}