Created
April 13, 2022 23:13
-
-
Save MeinLiX/e65d0db12064edf7964853bce6c4b45c to your computer and use it in GitHub Desktop.
TecomTech MLS 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; | |
var g_local = g("1+x3+x4", bitRate: 4); | |
List<bool> register0 = new() { true, true, true, true }; | |
printShiftRegister(g_local, @default: true); | |
printShiftRegister(g_local); | |
printTable(g_local, register0, 20); | |
List<bool> g(string x, int bitRate) | |
{ | |
List<bool> g = new(); | |
var polynomials = x.Split('+').SkipWhile(p => p.Equals("1") || p.Length < 2).Select(p => p[1..]).ToList(); | |
for (int i = 1; i <= bitRate; i++) | |
g.Add(polynomials.Contains($"{i}")); | |
return g; | |
} | |
string tableSide(int i) => new List<string>() { "─", "┴", "└", "┘" }[i]; | |
void printShiftRegister(List<bool> g, bool @default = false) | |
{ | |
StringBuilder sb = new(); | |
sb.Append(tableSide(2)); | |
if (@default is true) | |
{ | |
for (int i = 0; i < g.Count; i++) | |
sb.Append($"S{i + 1}{tableSide(1)}"); | |
Console.WriteLine("Default table:"); | |
} | |
else | |
{ | |
for (int i = 0; i < g.Count; i++) | |
sb.Append($"S{i + 1}{tableSide(Convert.ToInt32(g[i]))}"); | |
Console.WriteLine("Optimal table:"); | |
} | |
Console.WriteLine($"{sb.ToString()[..^1]}{tableSide(3)}"); | |
} | |
void printTable(List<bool> g_local, List<bool> register0, int times = 16) | |
{ | |
List<List<bool>> table = new(); | |
table.Add(register0); | |
for (int i = 0; i <= times; i++) | |
{ | |
table.Add(new List<bool>()); | |
bool? el1 = null; | |
g_local.Select((gi, idx) => (gi, idx)) | |
.Where(gi => gi.gi != false) | |
.ToList() | |
.ForEach(gi => | |
{ | |
if (el1 is null) | |
el1 = table[^2][gi.idx]; | |
else | |
el1 ^= table[^2][gi.idx]; | |
}); | |
table[^1].Add(el1 ?? false); | |
for (int j = 0; j < g_local.Count - 1; j++) | |
{ | |
table[^1].Add(table[^2][j]); | |
} | |
} | |
Console.WriteLine($"Time\t| {string.Join(" | ", Enumerable.Range(0, g_local.Count).Select(n => $"S{n + 1}"))}"); | |
table.Select((t, idx) => (t, idx)).ToList().ForEach(t => | |
{ | |
Console.WriteLine($"{t.idx} \t| {string.Join(" | ", t.t.Select(i => Convert.ToUInt16(i)))}"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment