Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AlphanumericEncoder.cs
2{
7 {
11 public const string AlphanumericCharacters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
12
13 private readonly BitWriter output;
14
20 {
21 this.output = Output;
22 }
23
29 public static bool CanEncode(string Text)
30 {
31 foreach (char ch in Text)
32 {
33 if (AlphanumericCharacters.IndexOf(ch) < 0)
34 return false;
35 }
36
37 return true;
38 }
39
44 public void Encode(string Text)
45 {
46 int i = 0;
47 int j;
48 int c = 0;
49
50 foreach (char ch in Text)
51 {
52 j = AlphanumericCharacters.IndexOf(ch);
53 if (j < 0)
54 continue;
55
56 i *= 45;
57 i += j;
58
59 if (++c >= 2)
60 {
61 this.output.WriteBits((uint)i, 11);
62 i = c = 0;
63 }
64 }
65
66 if (c == 1)
67 this.output.WriteBits((uint)i, 6);
68 }
69
76 public static int GetByteLength(int NrCharacters)
77 {
78 int NrBits = 11 * (NrCharacters / 2);
79 if ((NrCharacters & 1) != 0)
80 NrBits += 6;
81
82 return (NrBits + 7) / 8;
83 }
84 }
85}
static int GetByteLength(int NrCharacters)
Gets the number of bytes required to encode an alphanumeric message containing a specific number of c...
AlphanumericEncoder(BitWriter Output)
Encodes alphanumeric strings
const string AlphanumericCharacters
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:
static bool CanEncode(string Text)
Checks if a text string can be encoded using the alphanumeric encoding.
Writes a sequence of bits (Most significant bits first).
Definition: BitWriter.cs:10
Interface for text encoders.
Definition: ITextEncoder.cs:7