Created
April 13, 2022 21:12
-
-
Save MeinLiX/001dc314b1c1176f3e4fc081202a69ed to your computer and use it in GitHub Desktop.
TecomTechLab build: .NET 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text.RegularExpressions; | |
int variable = 2; | |
const int BITNESS = 16; | |
List<bool> result = new(); | |
List<List<int>> hadamar = GetHadamard(BITNESS); | |
List<int> w = hadamar[variable - 1]; | |
Regex.Replace( | |
File.ReadAllText(@"D:\MeinLiX\project\source\repos_cSph\MyLibs\TecomTechLab\TecomTechLab\DataBinary.dat"), | |
@"\s+", " ") | |
.Split(" ") | |
.Where(s => !string.IsNullOrEmpty(s)) | |
.Select(i => Convert.ToInt32(i)) | |
.Chunk(BITNESS) | |
.ToList() | |
.ForEach(musk => | |
{ | |
int sum = 0; | |
for (int i = 0; i < musk.Length; i++) | |
sum += musk[i] * w[i]; | |
result.Add((sum / BITNESS) > 0); | |
}); | |
Console.WriteLine($"Variable ({variable}): "); | |
Console.WriteLine(string.Join(" ", result.Select(i => Convert.ToInt16(i)))); | |
static List<List<int>> GetHadamard(int n) => n switch | |
{ | |
1 => new List<List<int>> { new List<int>() { 1 } }, | |
_ => GetHadamardNext(n) | |
}; | |
static List<List<int>> GetHadamardNext(int n) | |
{ | |
List<List<int>> result = new(GetHadamard(n / 2)); | |
for (int i = 0; i < result.Count; i++) | |
for (int j = 0; j < (n / 2); j++) | |
result[i].Add(result[i][j]); | |
for (int i = 0; i < (n / 2); i++) | |
{ | |
result.Add(new(result[i])); | |
for (int j = 0; j < (n / 2); j++) | |
result[(n / 2) + i][(n / 2) + j] = -result[(n / 2) + i][(n / 2) + j]; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment