Description of Algorithm
A simple algorithm works with & play with an ASCII value of characters.
Algorithm works within 6 different steps.
Step 1: Convert input string characters in respected ASCII codes & store it in array like below mentioned example of C# code.
- ArrayList asciiArr = new ArrayList();
- for (int i = 0; i < inputString.Length; i++) {
- asciiArr.Add((int) Convert.ToChar(inputString[i]));
- }
- or(i = 0; i < inputString.length; i++) {
- asciiArr[i] = inputString[i].charCodeAt(0);
- }
- ArrayList atozArr = new ArrayList();
- for (int i = 0, j = 65; i < 26; i++, j++)
- {
- atozArr.Add((char) j);
- }
Note: Here i'm referencing an function return a random value from minimum - maximum range.
int positionAscii = Convert.ToInt32(atozArr[(new Random()).Next(26)]);
Step 4: Addition of every input String each element to positionAscii.
- ArrayList outputArr = new ArrayList();
- for (int i = 0; i < inputString.Length; i++) {
- outputArr.Add(Convert.ToInt32(asciiArr[i]) + positionAscii);
- }
- int[] k = (int[]) outputArr.ToArray(System.Type.GetType("System.Int32"));
- Console.Write("\nCipher Text: \n\n");
- foreach(int i in k) {
- cipherText = cipherText + (char) i;
- }
- if (inputString.Length.Equals(cipherText.Length))
- {
- cipherText = cipherText + (char)positionAscii;
- }
- return cipherText;

For decryption process reverse steps apply.
Note: Every time cypher text will change due to selection of randomposition from A to Z.
Below mention code is print your output cipher text to text file.
- string output = "";
- // Write each directory name to a file.
- using (StreamWriter sw = new StreamWriter("output.txt"))
- {
- output = encryption(input);
- sw.WriteLine(output);
- }
- function encryption() {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Collections;
- using System.IO;
- namespace Codeblank {
- class Program {
- private static string encryption(string inputString) {
- string cipherText = "";
- //Step : 1
- //Convert input string characters in respected ascii codes & store it in array like below mentioned example of C# code.
- ArrayList asciiArr = new ArrayList();
- for (int i = 0; i < inputString.Length; i++) {
- asciiArr.Add((int) Convert.ToChar(inputString[i]));
- }
- //Step : 2
- //Fill A to Z array in capital or small letters
- ArrayList atozArr = new ArrayList();
- for (int i = 0, j = 65; i < 26; i++, j++) {
- atozArr.Add((char) j);
- }
- //Step : 3
- // Choose randomly single character index from A to Z and differentiate it's position in one variable & it's respected ascii value in second variable
- //Note: Here i'm referencing an function return a random value from minimum - maximum range.
- int positionAscii = Convert.ToInt32(atozArr[(new Random()).Next(26)]);
- //Step : 4
- //Addition of every input String each element to positionAscii
- ArrayList outputArr = new ArrayList();
- for (int i = 0; i < inputString.Length; i++) {
- outputArr.Add(Convert.ToInt32(asciiArr[i]) + positionAscii);
- }
- int[] k = (int[]) outputArr.ToArray(System.Type.GetType("System.Int32"));
- Console.Write("\nCipher Text: \n\n");
- foreach(int i in k) {
- cipherText = cipherText + (char) i;
- }
- //Step : 5
- //Attachment of key to encrypted string or not it's your choice & it's your modification scenario, here i'm attaching a key with an encrypted string
- if (inputString.Length.Equals(cipherText.Length)) {
- cipherText = cipherText + (char) positionAscii;
- }
- //Step : 6
- //Finally your encryption is ready to send
- return cipherText;
- }
- private static string decryption(string cipherText) {
- //Step : 1
- //Take decryption key from cipherText
- int positionAscii = Convert.ToInt32(cipherText[cipherText.Length - 1]);
- //Step : 2
- //Substract value of key from each characters of cipherText
- string plainText = "";
- foreach(int i in cipherText) {
- plainText = plainText + (char)(Convert.ToInt32(i) - positionAscii);
- }
- return plainText;
- }
- static void Main(string[] args) {
- Console.Write("Plain Text: \n\n");
- string input = Console.ReadLine();
- string output = "";
- // Write each directory name to a file.
- using(StreamWriter sw = new StreamWriter("output.txt")) {
- output = encryption(input);
- sw.WriteLine(output);
- }
- Console.Write(output);
- Console.WriteLine("\n\nAfter Decryption Plain Text: \n\n" + decryption(output));
- Console.ReadKey();
- }
- }
- }

Christian KursPosted Apr 20, 2021, 11:39 AM
Good Article for all Developers, they want Cryption.
Avikshith AradhyaPosted Jun 2, 2016, 7:16 AM
Good One
Michael GriffithsPosted Apr 1, 2016, 10:40 AM
Nice article. Very insightful
Sonu ChaudharyPosted Feb 25, 2016, 7:14 AM
nice article
Asif ZaffarPosted Feb 24, 2016, 6:26 AM
gr8 Jaydeep Bhai, it really helped me. what If I could need more help in coding