// [Fact] public void testing2_decode_function() { Assert.Equal("hey", HammingCode.decode("100111111000111001000010000111111000000111001111000111110110111000010111")); Assert.Equal("The Sensei told me that i can do this kata", HammingCode.decode("000111000111000111000100000111111000111000001000000111111000000111000111000100111000000000000000000111000111000000111111000111111000000111000111000111111000111111111000000111111111000000111111000110111000010111000111000111111000111001000111000000111000000000000000000111111111000111000000000111111000111111111111000111111000111111000000000111111000000111000001000000111000000000001000000111111000111111000111000111111000000111000111000000111000000000000000000111111111000111000000000111111000111000000000000111111000000010000111000111111111000111000000000100111000000000000000000111111000111000000111000000111000000000000000000111111000000000111111000111111000000000000111000111111000111111111000000000111000000000000010000111111000000111000000000111111000111111110111000000111000000000000000000111111111000111000000000111111000111000000000000111111000111000000111000111111111000000111111000000111000000000000000000111111000111000111111000111111000000000000111000111111111000111000000000111111000000000000111")); Assert.Equal("T3st", HammingCode.decode("000111000111000111000001000000111111000000111111000111111111000000111011000111111111000111000000")); Assert.Equal("T?st!%", HammingCode.decode("000111000111000111000010000000111111111111011111000111111111000000111111000111101111000111000000000000111000000000000111000000111000000111000111")); }
public Dictionary <KeyValuePair <int, int>, double> Compare(List <Color[, ]> imagesForComparison) { var reversibleKeys = new Dictionary <KeyValuePair <int, int>, bool>(); var result = new Dictionary <KeyValuePair <int, int>, double>(); var hashes = imagesForComparison.Select(CalculatePreceptiveHash).ToList(); for (var i = 0; i < hashes.Count; i++) { for (var j = 0; j < hashes.Count; j++) { if (i == j) { continue; } var verifyingKey = new KeyValuePair <int, int>(i, j); if (reversibleKeys.ContainsKey(verifyingKey)) { continue; } var numberDifferentBits = HammingCode.Calc(hashes[i], hashes[j]); result.Add(new KeyValuePair <int, int>(i, j), System.Math.Round(1 - numberDifferentBits / 64.0, 4)); var reverseKey = new KeyValuePair <int, int>(j, i); reversibleKeys[reverseKey] = true; } } return(result); }
public double Compare(Color[,] imageFirst, Color[,] imageSecond) { var hashImageFirst = CalculatePreceptiveHash(imageFirst); var hashImageSecond = CalculatePreceptiveHash(imageSecond); var numberDifferentBits = HammingCode.Calc(hashImageFirst, hashImageSecond); return(System.Math.Round(1 - numberDifferentBits / 64.0, 4)); }
private void btn2_Click(object sender, EventArgs e) { HammingCode hamming = new HammingCode(); if (checkParidad.Checked == true) { hamming.SetParity(1); } else { hamming.SetParity(0); } Console.WriteLine("-------------------------------------"); string code = ""; for (int con = 1; con < 18; con++) { code = code + ((DataRowView)dtGV1.Rows[0].DataBoundItem).DataView.Table.Rows[6][con].ToString(); } int[,] result = hamming.ErrorDetection(code); int[] error = hamming.errorArray; int[] originalParity = hamming.originalParity; int[] actualParity = hamming.currentParity; int errorBit = hamming.errorBit; for (int row = 0; row < 7; row++) { for (int col = 0; col < 17; col++) { int data = result[row, col]; if (data == 5) { continue; } else { ((DataRowView)dtGV2.Rows[0].DataBoundItem).DataView.Table.Rows[row][col + 1] = data; } } } for (int i = 0; i < 5; i++) { ((DataRowView)dtGV2.Rows[0].DataBoundItem).DataView.Table.Rows[i + 1][18] = error[i]; } lbError1.Text = "Error array :: " + string.Join("", error); lbError2.Text = "Paridad Original :: " + string.Join("", originalParity); lbError3.Text = "Paridad Calculada :: " + string.Join("", actualParity); lbError4.Text = "Bit del Error :: " + errorBit; Console.WriteLine("Error array :: " + string.Join("", error)); Console.WriteLine("Paridad Original :: " + string.Join("", originalParity)); Console.WriteLine("Paridad Calculada :: " + string.Join("", actualParity)); Console.WriteLine("Bit del Error :: " + errorBit); }
private double CalculateTheMeasureCoincidence(IReadOnlyList <ulong> firstImageHashes, IReadOnlyList <ulong> secondImageHashes) { var summaMeasures = 0.0; for (var i = 0; i < firstImageHashes.Count; i++) { summaMeasures += HammingCode.Calc(firstImageHashes[i], secondImageHashes[i]); } return(System.Math.Round(1 - summaMeasures / (firstImageHashes.Count * 64.0), 4)); }
private void btn1_Click(object sender, EventArgs e) { textBox1.Text = textBox1.Text.ToUpper(); string numero = textBox1.Text; int con = 0; if (numero.Length == 12) { while (con != numero.Length) { if (numero.Substring(con, 1) == "1" || numero.Substring(con, 1) == "0") { con++; } else { break; } } if (numero.Length == con) { HammingCode hamming = new HammingCode(); if (checkParidad.Checked == true) { hamming.SetParity(1); } else { hamming.SetParity(0); } int[,] result = hamming.DataEncoding(numero); for (int row = 0; row < 7; row++) { for (int col = 0; col < 17; col++) { int data = result[row, col]; if (data == 5) { continue; } else { ((DataRowView)dtGV1.Rows[0].DataBoundItem).DataView.Table.Rows[row][col + 1] = data; } } } btn2.Enabled = true; } else { Program.alert = new Alert(); Program.alert.Show(); } } else { Program.alert = new Alert(); Program.alert.Show(); } }
// [Fact] public void testing1_encode_function() { Assert.Equal("000111111000111000000000000111111000000111000111000111111111111000000111", HammingCode.encode("hey")); Assert.Equal("000111000111000111000000000111111000111000000000000111111000000111000111000000111000000000000000000111000111000000111111000111111000000111000111000111111000111111111000000111111111000000111111000111111000000111000111000111111000111000000111000000111000000000000000000111111111000111000000000111111000111111111111000111111000111111000000000111111000000111000000000000111000000000000000000111111000111111000111000111111000000111000111000000111000000000000000000111111111000111000000000111111000111000000000000111111000000000000111000111111111000111000000000000111000000000000000000111111000111000000111000000111000000000000000000111111000000000111111000111111000000000000111000111111000111111111000000000111000000000000000000111111000000111000000000111111000111111111111000000111000000000000000000111111111000111000000000111111000111000000000000111111000111000000111000111111111000000111111000000111000000000000000000111111000111000111111000111111000000000000111000111111111000111000000000111111000000000000111", HammingCode.encode("The Sensei told me that i can do this kata")); Assert.Equal("000111000111000111000000000000111111000000111111000111111111000000111111000111111111000111000000", HammingCode.encode("T3st")); Assert.Equal("000111000111000111000000000000111111111111111111000111111111000000111111000111111111000111000000000000111000000000000111000000111000000111000111", HammingCode.encode("T?st!%")); }