using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace vmpcv2
{
internal static class Coding
{
public static Tuple<byte[], byte> getKey(byte[] Vec, byte[] VecInit)
{
int v = Vec.Length;
int vi = VecInit.Length;
byte s = 0;
int n = 0;
byte[] P = new byte[255];
for (byte i = 0; i < P.Length; i++)
{
P[i] = i;
}
for (int m = 0; m < 768; m++)
{
n = m % 255;
s = P[(s + P[n] + Vec[m % v]) % 255];
var temp = P[n];
P[n] = P[s];
P[s] = temp;
}
for (int m = 0; m < 768; m++)
{
n = m % 255;
s = P[(s + P[n] + VecInit[m % vi]) % 255];
var temp = P[n];
P[n] = P[s];
P[s] = temp;
}
return Tuple.Create(P, s);
}
public static IEnumerable<byte> Encode(byte[] Key, byte[] Msg)
{
byte[] initv = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
};
byte n = 0;
int L = Key.Length;
Tuple<byte[], byte> kse = getKey(Key, initv);
byte s = kse.Item2;
byte[] P = kse.Item1;
for (int i = 0; i < L; i++)
{
s = P[(s + P[n]) % 255];
yield return P[(P[P[s]] + 1) % 255];
var temp = P[n];
P[n] = P[s];
P[s] = temp;
n++;
}
}
}
}
Mam coś takiego, ale nie działa to do końca poprawnie, proszę o pomoc.
Jak mam udowodnić, że VMPC nie jest zawsze funkcją różnowartościową?
tutaj pomocnicze materiały: http://www.pieknafunkcja.pl/publi/VMPC_Enigma_2005.pdf