rest
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace Converting
|
||||
{
|
||||
public class Conv
|
||||
{
|
||||
public delegate void PositionEventHandler(object sender, int pos);
|
||||
public event PositionEventHandler OnNewPosition;
|
||||
public delegate void FinishEventHandler(object sender, int exitcode);
|
||||
public event FinishEventHandler OnFinish;
|
||||
public void ConvertFile(String input, String output, bool encode)
|
||||
{
|
||||
BinaryReader reader = new BinaryReader(File.Open(input, FileMode.Open));
|
||||
BinaryWriter writer = new BinaryWriter(File.Open(output, FileMode.Create));
|
||||
Converter conv = new Converter();
|
||||
int i = 0;
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
byte inp = reader.ReadByte();
|
||||
byte oup = 0;
|
||||
if (encode)
|
||||
{
|
||||
oup = conv.encoding((byte)i++, inp);
|
||||
}
|
||||
else
|
||||
{
|
||||
oup = conv.decoding((byte)i++, inp);
|
||||
}
|
||||
if (this.OnNewPosition != null)
|
||||
{
|
||||
this.OnNewPosition(this, i);
|
||||
}
|
||||
writer.Write(oup);
|
||||
//System.Threading.Thread.Sleep(1);
|
||||
}
|
||||
}
|
||||
catch (EndOfStreamException) { }
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
if (this.OnFinish != null)
|
||||
{
|
||||
this.OnFinish(this, 1);
|
||||
reader.Close();
|
||||
writer.Close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.OnFinish != null)
|
||||
{
|
||||
this.OnFinish(this, 0);
|
||||
reader.Close();
|
||||
writer.Close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Converting
|
||||
{
|
||||
class Converter
|
||||
{
|
||||
private Dictionary<Tuple<byte, byte>, byte> enc = new Dictionary<Tuple<byte, byte>, byte>();
|
||||
private Dictionary<Tuple<byte, byte>, byte> dec = new Dictionary<Tuple<byte, byte>, byte>();
|
||||
private static byte[] encode = { 0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03 };
|
||||
private static byte[] decode = { 0x09, 0x0A, 0x0B, 0x0C, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x0D, 0x0E, 0x0F, 0x00 };
|
||||
public static byte conv(byte pos, byte value, bool enc = true)
|
||||
{
|
||||
byte ret = 0;
|
||||
//pos / 8;
|
||||
//int offset_high = 14;
|
||||
//int offset_low = 0;
|
||||
|
||||
//int offset_high = 14;
|
||||
|
||||
int offset_high = 0;
|
||||
int offset_low = 0;
|
||||
|
||||
if (enc)
|
||||
{
|
||||
offset_high = (14 - (pos / 16) >= 0) ? 14 - (pos / 16) : 15;
|
||||
offset_low = (14 - (pos % 16) >= 0) ? 14 - (pos % 16) : 15;
|
||||
if (pos % 16 == 15)
|
||||
{
|
||||
offset_high = (offset_high - 1 >= 0) ? offset_high - 1 : 15;
|
||||
}
|
||||
offset_high = offset_high % 16;
|
||||
offset_high = offset_high + (((value / 8) + offset_low) / 16);
|
||||
|
||||
int ol = ((value / 8) + offset_low) % 16;
|
||||
int oh = ((((value & 0x0F) & 0x7) * 2) + offset_high) % 16;
|
||||
|
||||
ret = (byte)(encode[oh] << 4);
|
||||
ret = (byte)(ret | encode[ol]);
|
||||
}
|
||||
else
|
||||
{
|
||||
offset_low = decode[(pos+1)%16];
|
||||
offset_high = ((pos / 16)+1)%16;
|
||||
if (pos % 16 == 15)
|
||||
{
|
||||
offset_high = (offset_high + 1) % 16;
|
||||
}
|
||||
offset_high = decode[offset_high];
|
||||
|
||||
byte nh = (byte)(value >> 4);
|
||||
byte nl = (byte)(value & 0x0F);
|
||||
|
||||
int oh = (nh + offset_high) % 16;
|
||||
int ol = (nl + offset_low) % 16;
|
||||
|
||||
|
||||
ret = (byte)(encode[oh] << 4);
|
||||
ret = (byte)(ret | encode[ol]);
|
||||
}
|
||||
//int offset_high = pos + 1;
|
||||
//int offset_low = 1;
|
||||
|
||||
//int offset_low = (offset_high / 16) + 1;
|
||||
|
||||
//byte n1 = (byte)(value >> 4);
|
||||
//byte n2 = (byte)(value & 0x0F);
|
||||
//int over = (((value / 8) + offset_low) / 16) % 2;
|
||||
//ret = (byte)(nibble_high[(((value & 0x0F) & 0x7) + offset_high) % 8] + over << 4);
|
||||
return ret;
|
||||
}
|
||||
public Converter()
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
for (int j = 0; j < 256; j++)
|
||||
{
|
||||
enc.Add(new Tuple<byte, byte>((byte)i, (byte)j), conv((byte)i, (byte)j, true));
|
||||
dec.Add(new Tuple<byte, byte>((byte)i, conv((byte)i, (byte)j, true)), (byte)j);
|
||||
}
|
||||
}
|
||||
}
|
||||
public byte encoding(byte pos, byte value)
|
||||
{
|
||||
return enc[new Tuple<byte, byte>(pos, value)];
|
||||
}
|
||||
public byte decoding(byte pos, byte value)
|
||||
{
|
||||
return dec[new Tuple<byte, byte>(pos, value)];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{53BF135E-D9AA-48ED-9139-BCECAF89A1AF}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Converting</RootNamespace>
|
||||
<AssemblyName>Converting</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Conv.cs" />
|
||||
<Compile Include="Converter.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
[assembly: AssemblyTitle("Converting")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Converting")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("35b2f8f7-0ddd-40a8-91ca-d7cce7f53dae")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Reference in New Issue
Block a user