HI, i've c# at school and some kind of noob did 'program' this 'Encryption' way.
Thought I was unable to help him to get rid of these Errors he gets.
Since I really love to know what the answer is.
And NO this is not me asking help.
Im posting this for a clasmate..
Anyhow, Please Help ^^
Code:using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Security.Cryptography; namespace EncryptionAlgorytmn { class Program { public string base64Encode(string data) { try { byte[] encData_byte = new byte[data.Length]; encData_byte = System.Text.Encoding.UTF8.GetBytes(data); string encodedData = Convert.ToBase64String(encData_byte); return encodedData; } catch (Exception e) { throw new Exception("Error in base64Encode" + e.Message); } } public string strReverse(string s) { int j = 0; char[] c = new char[s.Length]; for (int i = s.Length - 1; i >= 0; i--) c[j++] = s[i]; return new string(c); } public static string EncryptData(byte[] desKey, byte[] desIV, string data) { MemoryStream output = new MemoryStream(); byte[] byteData = new UnicodeEncoding().GetBytes(data); TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); CryptoStream crypt = new CryptoStream(output, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write); crypt.Write(byteData, 0, byteData.Length); crypt.Close(); output.Close(); return new UnicodeEncoding().GetString(output.ToArray()); } static void Main(string[] args) { string Encrypted, z; bool rev; int x = 1, y = 1; const string HIDDEN_ENCRYPTION_KEY = "0xF4E"; Console.WriteLine("Enter Password you want to Encrypt:"); Encrypted = Console.ReadLine(); for(int i = 0; i < 10; i++) { if (x == 5) { x = 1; } x++; switch (x) { case 1: y = 7; break; case 2: y = 2; break; case 3: y = 9; break; case 4: y = 1; break; case 5: y = 6; break; default: y = 0; break; } Encrypted = base64Encode(Encrypted); if (rev == true) { Encrypted = strReverse(Encrypted); rev = false; } else { Encrypted = Encrypted + HIDDEN_ENCRYPTION_KEY; rev = true; } if ((i % 2) != 0) { Encrypted = EncryptData(x, y, Encrypted); } } z = strReverse(Encrypted); z = HIDDEN_ENCRYPTION_KEY + Encrypted + HIDDEN_ENCRYPTION_KEY; Encrypted = (strReverse(z) + strReverse(Encrypted) + HIDDEN_ENCRYPTION_KEY.ToUpper()); Console.Write("Encrypted Key: "); Console.WriteLine(Encrypted); Console.Write("Value z: "); Console.WriteLine(z); Console.Write("Value rev: "); Console.WriteLine(rev); Console.Write("Value x: "); Console.WriteLine(x); Console.Write("Value y: "); Console.WriteLine(y); Console.ReadKey(); } } }




Reply With Quote