Simple string encryption or decryption

Here we will write code for encryption of any given input to the different character.


Example: if user input a it will convert to e next 4 charactor
if user enter z it will convert to d

Suppose if user input abcxyz it will be converted to efgbcd


Below code snippet will do the same

var userInput = ReadLine().ToLower();
char[] array = new char[userInput.Length];

for (int i = 0; i < userInput.Length; i++)
{
  var current = (int)userInput[i];
  //97(a) to 122(z)
  if (current > 96 && current < 119)
  {
	array[i] = (char)(current + 4);
  }
  else if (current > 118 && current < 123)
  {
	array[i] = (char)(current - 22);
  }
}
Console.WriteLine(array);

4 thoughts on “Simple string encryption or decryption”

  1. Hey there! This is kind of off topic but I need some help from an established blog. Is it difficult to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about creating my own but I’m not sure where to begin. Do you have any tips or suggestions? With thanks

Leave a Reply

Your email address will not be published. Required fields are marked *