Skip to main content

forward_only

// Create Forward-only Decoder
// For this sample sequence window is being set to 2
MteDec decoderF = new MteDec(0, 2);

// Instantiate the Decoder
decoderF.SetEntropy(entropy);
decoderF.SetNonce(0);
status = decoderF.Instantiate(personal);
if (status != MteStatus.mte_status_success) {
Console.Error.WriteLine("Decoder instantiate error ({0}): {1}",
decoderV.GetStatusName(status),
decoderV.GetStatusDescription(status));
return (int)status;
}

// String to decode to.
string decoded;

// Create the corrupt version of message #2.
// Doing this to ensure decode fails
char first = encodings[2][0];
++first;
string corrupt =
encodings[2].Substring(1).Insert(0, new string(first, 1));

// Output that decoding is in forward-only sequencing mode
Console.WriteLine("\nForward-only mode (sequence window = 2):");

// Decode first message
// Output: Decode #1: mte_status_success, message 1
decoded = decoderF.DecodeStrB64(encodings[0], out status);
Console.WriteLine("Decode #1: {0}, {1}",
decoderF.GetStatusName(status),
decoded);

// Decode first message again -- out of sequence, should not work
// Output: Decode #1: mte_status_seq_outside_window,
decoded = decoderF.DecodeStrB64(encodings[0], out status);
Console.WriteLine("Decode #1: {0}, {1}",
decoderF.GetStatusName(status),
decoded);

// Decode corrupt message,
// Try to decode the corrupted second message -- should not work
// Output: Corrupt #3: mte_status_seq_mismatch,
decoded = decoderF.DecodeStrB64(corrupt, out status);
Console.WriteLine("Corrupt #3: {0}, {1}",
decoderF.GetStatusName(status),
decoded);

// Decode third message (within sequence window)
// Output: Decode #3: mte_status_success, message 3
decoded = decoderF.DecodeStrB64(encodings[2], out status);
Console.WriteLine("Decode #3: {0}, {1}",
decoderF.GetStatusName(status),
decoded);

// Decode non-corrupted second message
// (after already decoding third -- out of sequence)
// Output: Decode #2: mte_status_seq_outside_window,
decoded = decoderF.DecodeStrB64(encodings[1], out status);
Console.WriteLine("Decode #2: {0}, {1}",
decoderF.GetStatusName(status),
decoded);

// Decode third message again -- out of sequence, should not work
// Output: Decode #3: mte_status_seq_outside_window,
decoded = decoderF.DecodeStrB64(encodings[2], out status);
Console.WriteLine("Decode #3: {0}, {1}",
decoderF.GetStatusName(status),
decoded);

// Decode fourth message
// Output: Decode #4: mte_status_success, message 4
decoded = decoderF.DecodeStrB64(encodings[3], out status);
Console.WriteLine("Decode #4: {0}, {1}",
decoderF.GetStatusName(status),
decoded);