Found this on my computer.
This is to decode script files.
One of the imports is commented out as ****.
This is because MPGH does it. Fix it yourself!
C#:
Code:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Text;
using System****;
public class Crypt
{
public string Decode(string sText)
{
byte[] bytes = Encoding.ASCII.GetBytes(sText);
this.HexToString(ref bytes);
this.XorCrypt(ref bytes);
return Encoding.ASCII.GetString(bytes);
}
public bool DecodeFile(string sOpen, string sSafe)
{
try {
byte[] sData = this.loadFile(sOpen);
this.HexToString(ref sData);
this.XorCrypt(ref sData);
this.saveFile(sSafe, sData);
return true;
} catch (Exception obj1) {
return false;
}
}
public string Encode(string sText)
{
byte[] bytes = Encoding.ASCII.GetBytes(sText);
this.XorCrypt(ref bytes);
this.StringToHex(ref bytes);
return Encoding.ASCII.GetString(bytes);
}
public bool EncodeFile(string sOpen, string sSafe)
{
try {
byte[] sString = this.loadFile(sOpen);
this.XorCrypt(ref sString);
this.StringToHex(ref sString);
this.saveFile(sSafe, sString);
return true;
} catch (Exception obj1) {
return false;
}
}
private void HexToString(ref byte[] sData)
{
string str = Encoding.Default.GetString(sData);
byte[] buffer = new byte[(str.Length / 2)];
int i = 0;
for (i = 0; i <= buffer.Length - 1; i++) {
buffer[i] = Convert.ToByte(str.Substring((i * 2), 2), 0x10);
}
sData = buffer;
}
private byte[] loadFile(string sPath)
{
StreamReader reader = new StreamReader(sPath, Encoding.Default, true);
string s = reader.ReadToEnd();
reader.Close();
return Encoding.Default.GetBytes(s);
}
private void saveFile(string sPath, byte[] sData)
{
StreamWriter writer = new StreamWriter(sPath);
writer.Write(Encoding.Default.GetString(sData));
writer.Close();
}
private void StringToHex(ref byte[] sData)
{
StringBuilder builder = new StringBuilder((sData.Length * 2));
byte num = 0;
foreach (byte num_loopVariable in sData) {
num = num_loopVariable;
builder.AppendFormat("{0:X2}", num);
}
sData = Encoding.Default.GetBytes(builder.ToString());
}
public void XorCrypt(ref byte[] sString)
{
int i = 0;
for (i = 0; i <= sString.Length - 1; i++) {
sString[i] = Convert.ToByte(Convert.ToInt32((sString[i] ^ 0xd7)));
}
}
}
.NET
Code:
Imports System.Text
Imports System****
Public Class Crypt
Public Function Decode(ByVal sText As String) As String
Dim bytes As Byte() = Encoding.ASCII.GetBytes(sText)
Me.HexToString(bytes)
Me.XorCrypt(bytes)
Return Encoding.ASCII.GetString(bytes)
End Function
Public Function DecodeFile(ByVal sOpen As String, ByVal sSafe As String) As Boolean
Try
Dim sData As Byte() = Me.loadFile(sOpen)
Me.HexToString(sData)
Me.XorCrypt(sData)
Me.saveFile(sSafe, sData)
Return True
Catch obj1 As Exception
Return False
End Try
End Function
Public Function Encode(ByVal sText As String) As String
Dim bytes As Byte() = Encoding.ASCII.GetBytes(sText)
Me.XorCrypt(bytes)
Me.StringToHex(bytes)
Return Encoding.ASCII.GetString(bytes)
End Function
Public Function EncodeFile(ByVal sOpen As String, ByVal sSafe As String) As Boolean
Try
Dim sString As Byte() = Me.loadFile(sOpen)
Me.XorCrypt(sString)
Me.StringToHex(sString)
Me.saveFile(sSafe, sString)
Return True
Catch obj1 As Exception
Return False
End Try
End Function
Private Sub HexToString(ByRef sData As Byte())
Dim str As String = Encoding.Default.GetString(sData)
Dim buffer As Byte() = New Byte((str.Length / 2) - 1) {}
Dim i As Integer
For i = 0 To buffer.Length - 1
buffer(i) = Convert.ToByte(str.Substring((i * 2), 2), &H10)
Next i
sData = buffer
End Sub
Private Function loadFile(ByVal sPath As String) As Byte()
Dim reader As New StreamReader(sPath, Encoding.Default, True)
Dim s As String = reader.ReadToEnd
reader.Close()
Return Encoding.Default.GetBytes(s)
End Function
Private Sub saveFile(ByVal sPath As String, ByVal sData As Byte())
Dim writer As New StreamWriter(sPath)
writer.Write(Encoding.Default.GetString(sData))
writer.Close()
End Sub
Private Sub StringToHex(ByRef sData As Byte())
Dim builder As New StringBuilder((sData.Length * 2))
Dim num As Byte
For Each num In sData
builder.AppendFormat("{0:X2}", num)
Next
sData = Encoding.Default.GetBytes(builder.ToString)
End Sub
Public Sub XorCrypt(ByRef sString As Byte())
Dim i As Integer
For i = 0 To sString.Length - 1
sString(i) = Convert.ToByte(CInt((sString(i) Xor &HD7)))
Next i
End Sub
End Class
Take no credits.