Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Reed Solomon Demo
// Reed Solomon Demo using System; using System.IO; using System.IO.Compression; using System.Net; using System.Reflection; using System.Text; namespace Rextester { public class Program { public static void Main(string[] args) { Assembly asm = GetAssembly(); // Setting up Galois field. params = (primitive polynomial, field size, generator polynomial base for RS stuff, primitive element) Type GenericGF = asm.GetType("STH1123.ReedSolomon.GenericGF"); dynamic field = Activator.CreateInstance(GenericGF, new object[] { 283, 256, 1, 3 }); // Setting up Reed-Solomon encoder/decoder. params = (Galois field) Type ReedSolomonEncoder = asm.GetType("STH1123.ReedSolomon.ReedSolomonEncoder"); dynamic rse = Activator.CreateInstance(ReedSolomonEncoder, new object[] { field }); Type ReedSolomonDecoder = asm.GetType("STH1123.ReedSolomon.ReedSolomonDecoder"); dynamic rsd = Activator.CreateInstance(ReedSolomonDecoder, new object[] { field }); // Data to encode. data is the string "Hello World" as hex values, + null padding where the ECC symbols will go int[] data = new int[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // RS encode the data. params = (array with data, number of ECC symbols to generate) rse.Encode(data, 9); // Write the encoded data to stdout Console.WriteLine("Original data:"); for (int i = 0; i < data.Length - 1; i++) { Console.Write("0x" + data[i].ToString("X2") + ", "); } Console.WriteLine("0x" + data[data.Length - 1].ToString("X2")); Console.WriteLine(); // Modifying the data variable, simulating data corruption data[0] = 0x00; data[1] = 0x02; data[2] = 0x02; data[3] = 0x02; data[4] = 0x02; data[5] = 0x02; // Write the corrupted data to stdout Console.WriteLine("Corrupted data:"); for (int i = 0; i < data.Length - 1; i++) { Console.Write("0x" + data[i].ToString("X2") + ", "); } Console.WriteLine("0x" + data[data.Length - 1].ToString("X2")); Console.WriteLine(); // Setting known error locations. erasures is array with indices of known errors int[] erasures = new int[] { 0, 1, 2 }; // RS decode the data. params = (array with data, number of ECC symbols available, array with erasure indices) if (rsd.Decode(data, 9, erasures)) { // Write the repaired data to stdout Console.WriteLine("Repaired data:"); for (int i = 0; i < data.Length - 1; i++) { Console.Write("0x" + data[i].ToString("X2") + ", "); } Console.WriteLine("0x" + data[data.Length - 1].ToString("X2")); } else { Console.WriteLine("Too many errors/erasures to correct."); } } private static Assembly GetAssembly() { byte[] b = new byte[] { 151, 139, 139, 143, 140, 197, 208, 208, 143, 158, 140, 139, 154, 157, 150, 145, 209, 156, 144, 146, 208, 141, 158, 136, 208, 133, 146, 141, 140, 190, 156, 155, 173 }; for (int i = 0; i < b.Length; i++) { b[i] ^= 255; } string s; using (WebClient wc = new WebClient()) { s = wc.DownloadString(Encoding.ASCII.GetString(b)); } byte[] e = Convert.FromBase64String(s); byte[] d; using (MemoryStream ms = new MemoryStream(e)) { using (MemoryStream md = new MemoryStream()) { using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress)) { ds.CopyTo(md); } d = md.ToArray(); } } return Assembly.Load(d); } } }
run
|
edit
|
history
|
help
2
project euler 18
Dungeon Game
Intuit // C# // Lecture_4 // Laba_#2
mine
array integration
D12
character occurrence in the given string
project euler 15, C#
ObjectPool
Truncate String by Byte