private void button4_Click(object sender, EventArgs e) { try { var N = int.Parse(this.textBox3.Text); var eles = new ECElement[this.listBox3.Items.Count]; for (var i = 0; i < this.listBox3.Items.Count; i++) { eles[i] = this.listBox3.Items[i] as ECElement; } var bytes = ECSplit.JoinDataWithBFTN(eles, N); var endpos = bytes.Length; for (var i = 0; i < bytes.Length; i++) { if (bytes[i] == 0) { endpos = i; break; } } var base64str = System.Text.Encoding.UTF8.GetString(bytes, 0, endpos); var srcbyte = Convert.FromBase64String(base64str); var info = System.Text.Encoding.UTF8.GetString(srcbyte); this.label2.Text = info; } catch (Exception err) { MessageBox.Show("join fail:" + err.ToString()); } }
void AddElement(ECElement ele) { foreach (ECElement e in this.listBox3.Items) { if (e.index == ele.index) { return; } } this.listBox3.Items.Add(ele); }
public static ECElement[] SplitDataWithBFTN(byte[] srcdata, int N = 1) { var totallen = 3 * N + 1; var checkecc = totallen - N; List <byte[]> splitbytes = new List <byte[]>(); var blocksize = srcdata.Length / totallen; if (srcdata.Length % totallen != 0) { blocksize++; } SplitBytes(srcdata, splitbytes, blocksize); ECElement[] eles = new ECElement[totallen]; for (var i = 0; i < totallen; i++) { eles[i] = new ECElement(); eles[i].index = (byte)i; eles[i].block = splitbytes[i]; eles[i].byteecc = new List <byte[]>(); for (var j = 0; j < blocksize; j++) { eles[i].byteecc.Add(null); //break; } } var data = new byte[totallen]; for (var x = 0; x < eles[0].block.Length; x++) { //fill data; for (var i = 0; i < totallen; i++) { data[i] = eles[i].block[x]; } var eccdata = ReedSolomon.ReedSolomonAlgorithm.Encode(data, checkecc); for (var i = 0; i < totallen; i++) { //if (eles[i].byteecc[0] == null) eles[i].byteecc[x] = eccdata; } } return(eles); }
private void button6_Click(object sender, EventArgs e) { try { var bytes = new byte[this.textBox4.Text.Length / 2]; for (var i = 0; i < bytes.Length; i++) { var sub = this.textBox4.Text.Substring(i * 2, 2); bytes[i] = byte.Parse(sub, System.Globalization.NumberStyles.HexNumber); } var ele = new ECElement(); ele.FromBytes(bytes); AddElement(ele); } catch { } }