 [C#][VB .NET][SRC]Polymorphic Encryption Class - Printable Version +- Computer Tech (http://computertech.createmybb3.com) +-- Forum: Programming (/forumdisplay.php?fid=6) +--- Forum: .Net Programming (/forumdisplay.php?fid=8) +--- Thread: [C#][VB .NET][SRC]Polymorphic Encryption Class (/showthread.php?tid=121) [C#][VB .NET][SRC]Polymorphic Encryption Class - Ethereal - 01-16-2011 12:48 PM This is my own simple Polymorphic encryption class, released to you for free. I am not going to explain how it works, because if you are interested in writing your own class, you should already know enough to be able to understand this. Anyway, without further ado, here it is. Example of Polymorphism: [yt]http://www.youtube.com/watch?v=mCWruqZe0xk[/yt] C# Code: ```class PolyEncryption {     public string EncryptText(string input, string key)     {   ///   ///This function Polymorphically encrypts the entered Text, utilising a Key and Salt.   ///All credits to Ethereal of HackForums.net   ///Please leave the credits.   ///   Random R = new Random();   int kc = 0;   char[] text = input.ToCharArray();   char[] keyarr = key.ToCharArray();   char[] FinVal = new char[input.Length + 1];   int Rnd = R.Next(100, 220);   for (int index = 0; index < input.Length; index++)   {     if (kc >= keyarr.Length)     kc = 0;     int ptVal = (int)text[index];     int kVal = (int)keyarr[kc];     int ciVal = ptVal + kVal + Rnd;     FinVal[index] = Convert.ToChar(ciVal);     kc++;   }   FinVal[input.Length] = (char)Rnd;   string RetStr = new string(FinVal);   return RetStr;     }     public string DecryptText(string input, string key)     {   ///   ///This function decrypts text that was encrypted with the Polymorphic encrypter in this class.   ///All credits to Ethereal of HackForums.net   ///Please leave the credits.   ///   char[] text = input.ToCharArray();   char[] keyarr = key.ToCharArray();   char[] FinVal = new char[input.Length - 1];   int RndKVal = text[input.Length - 1];   text[input.Length - 1] = '\0';   int kc = 0;   for (int index = 0; index < input.Length; index++)   {     if (index >= input.Length - 1)     continue;     if (kc >= keyarr.Length)     kc = 0;     int ciVal = text[index];     int kVal = keyarr[kc];     int ptVal = ciVal - RndKVal - kVal;     FinVal[index] = Convert.ToChar(ptVal);     kc++;   }   string RetStr = new string(FinVal);   return RetStr;     } }``` Usage: Code: ```txtBox.Text = PolyEncryption.EncryptText("Test text", "TestKeyVal"); txtBox.Text = PolyEncryption.DecryptText("Test text", "TestKeyVal");``` VB .NET(no1me translated) Code: ```Class PolyEncryption     Public Function EncryptText(ByVal input As String, ByVal key As String) As String   'This function Polymorphically encrypts the entered Text, utilising a Key and Salt.   'All credits to Ethereal of HackForums.net   'Please leave the credits.   Dim R As New Random()   Dim kc As Integer = 0   Dim text As Char() = input.ToCharArray()   Dim keyarr As Char() = key.ToCharArray()   Dim FinVal As Char() = New Char(input.Length) {}   Dim Rnd As Integer = R.[Next](100, 220)   For index As Integer = 0 To input.Length - 1     If kc >= keyarr.Length Then     kc = 0     End If     Dim ptVal As Integer = AscW(text(index))     Dim kVal As Integer = AscW(keyarr(kc))     Dim ciVal As Integer = ptVal + kVal + Rnd     FinVal(index) = Convert.ToChar(ciVal)     kc += 1   Next   FinVal(input.Length) = ChrW(Rnd)   Dim RetStr As New String(FinVal)   Return RetStr     End Function     Public Function DecryptText(ByVal input As String, ByVal key As String) As String   'This function decrypts text that was encrypted with the Polymorphic encrypter in this class.   'All credits to Ethereal of HackForums.net   'Please leave the credits.   Dim text As Char() = input.ToCharArray()   Dim keyarr As Char() = key.ToCharArray()   Dim FinVal As Char() = New Char(input.Length - 2) {}   Dim RndKVal As Integer = AscW(text(input.Length - 1))   text(input.Length - 1) = ControlChars.NullChar   Dim kc As Integer = 0   For index As Integer = 0 To input.Length - 1     If index >= input.Length - 1 Then     Continue For     End If     If kc >= keyarr.Length Then     kc = 0     End If     Dim ciVal As Integer = AscW(text(index))     Dim kVal As Integer = AscW(keyarr(kc))     Dim ptVal As Integer = ciVal - RndKVal - kVal     FinVal(index) = Convert.ToChar(ptVal)     kc += 1   Next   Dim RetStr As New String(FinVal)   Return RetStr     End Function End Class``` Usage: Code: ```TextBox1.Text = PolyEncryption.EncryptText(TextBox1.Text, TextBox3.Text) TextBox1.Text = PolyEncryption.DecryptText(TextBox1.Text, TextBox3.Text)``` I hope that it is useful to you. RE: [C#][SRC]Polymorphic Encryption Class - Ironside - 01-16-2011 12:51 PM Nice, this will definitely help me learn Polymorphism. RE: [C#][SRC]Polymorphic Encryption Class - Hidden Dragon - 01-16-2011 04:45 PM Thanks for sharing. The only polymorphism I knew how to use before was polymorphism when one name could refer to multiple things. RE: [C#][SRC]Polymorphic Encryption Class - Ethereal - 01-16-2011 05:48 PM (01-16-2011 04:45 PM)Hidden Dragon Wrote:  Thanks for sharing. The only polymorphism I knew how to use before was polymorphism when one name could refer to multiple things. Function overloading? Anyways, I switched the goto for a continue, so be sure to use the slightly updated code. RE: [C#][SRC]Polymorphic Encryption Class - Hidden Dragon - 01-16-2011 05:55 PM Well yes it would be overloading.