Post Reply 
Social Buttons
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C#][VB .NET][SRC]Polymorphic Encryption Class
Author Message
Ethereal Offline
Moderator
*******

Trade Count: (0)
Posts: 39
Joined: Jan 2011
Reputation: 5
Post: #1
[C#][VB .NET][SRC]Polymorphic Encryption Class
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)
    {
  ///<summary>
  ///This function Polymorphically encrypts the entered Text, utilising a Key and Salt.
  ///All credits to Ethereal of HackForums.net
  ///Please leave the credits.
  ///</summary>
  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)
    {
  ///<summary>
  ///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.
  ///</summary>
  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.
(This post was last modified: 01-16-2011 08:55 PM by Ethereal.)
01-16-2011 12:48 PM
Find all posts by this user Quote this message in a reply
Ironside Offline
Site Owner
**********

Trade Count: (0)
Posts: 170
Joined: Nov 2010
Reputation: 7
Post: #2
RE: [C#][SRC]Polymorphic Encryption Class
Nice, this will definitely help me learn Polymorphism.
01-16-2011 12:51 PM
Find all posts by this user Quote this message in a reply
Hidden Dragon Offline
Amazing
*******

Trade Count: (0)
Posts: 63
Joined: Jan 2011
Reputation: 4
Post: #3
RE: [C#][SRC]Polymorphic Encryption Class
Thanks for sharing. The only polymorphism I knew how to use before was polymorphism when one name could refer to multiple things.
01-16-2011 04:45 PM
Find all posts by this user Quote this message in a reply
Ethereal Offline
Moderator
*******

Trade Count: (0)
Posts: 39
Joined: Jan 2011
Reputation: 5
Post: #4
RE: [C#][SRC]Polymorphic Encryption Class
(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.
01-16-2011 05:48 PM
Find all posts by this user Quote this message in a reply
Hidden Dragon Offline
Amazing
*******

Trade Count: (0)
Posts: 63
Joined: Jan 2011
Reputation: 4
Post: #5
RE: [C#][SRC]Polymorphic Encryption Class
Well yes it would be overloading.
01-16-2011 05:55 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: