[C#][VB.NET][SRC]Polymorphic Encryption Class - Ethereal - Jan 16, 2011
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:
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;
}
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
Very interesting Ethereal, nice to see another C# coder also.
* - no1me - Jan 16, 2011
work very good
vb.net if s1 want
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = EncryptText(TextBox1.Text, TextBox3.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox2.Text = DecryptText(TextBox1.Text, TextBox3.Text)
End Sub
End Class
(Jan 16, 2011 12:26 PM)no1me Wrote: work very good
vb.net if s1 want
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = EncryptText(TextBox1.Text, TextBox3.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox2.Text = DecryptText(TextBox1.Text, TextBox3.Text)
End Sub
End Class
tnx
Updated original post with this.
(Jan 16, 2011 11:30 AM)Guard Wrote: Very interesting Ethereal, nice to see another C# coder also.