i was going through encryption today and my colleague told me a simpler/custom way to do it, what i did is listed down there, so can you please tell me what type of encryption or hashign is that? he told me that this is the mixture of some sort of hashing and encryption. Sorry for stupid question i am new here. 🙂
the below method takes a string (password in my case). reverses it and makes a dictionary (adding dictionary items are listed below) and matches the keys and values and return encrypted data.
public static string Encrypt(string source)
{
string enCrypted = "";
try
{
source = Reverse(source);
Dictionary<char, char> sourceTable = AddDictionaryItems();
char[] sourceArray = source.ToCharArray();
StringBuilder encryptedData = new StringBuilder();
foreach (char chr in sourceArray)
{
KeyValuePair<char, char> Pair;
Pair = sourceTable.First(tuple => tuple.Key == chr);
encryptedData.Append(Pair.Value);
}
enCrypted=encryptedData.ToString();
}
catch (Exception ex)
{
}
return enCrypted;
}
the below method adds items into dictionary, items are basically based on ascii codes. i loop through all asciis and then corresponding charachters are added in the dictionary. but the real trick is that when adding an item in the dictionary. e.g., when i add ‘A’ in dictionary as a key, then its value would be ‘D’. the variable “jump” specifies the difference between key and value. so if my password is ‘ABC’ it would return ‘DEF’ or ‘FED’ if i reverse that thing.
public static Dictionary<char, char> AddDictionaryItems()
{
Dictionary<char, char> dc = new Dictionary<char, char>();
try
{
int initial = 33;
int jump = 3;
int final = 127 - jump;
for (int ascii = initial; ascii < final; ascii++)
{
dc.Add((char)ascii, (char)(ascii + jump));
}
for (int ascii = final; ascii < final + jump; ascii++)
{
dc.Add((char)ascii, (char)(initial));
initial++;
}
}
catch (Exception ex)
{
throw ex;
}
return dc;
}
That would be a Substitution Cipher, however unless you are making this for fun, do not use this method for anything that requires security. 1000’s of people crack this encryption method every day for fun (check your local newspaper, it likely has one too, it is usually next to the crossword).