szyfrowanie vigenere / pomoc w zrozumieniu

0

Witam
Mam procedury szyfrowania i deszyfrowania według alg vigenere, gdzie:

Szyfrowanie:

public static Byte[] encryptByteVigenere(Byte[] plaintext, string key) 
{

    Byte[] result= new Byte[plaintext.Length];

    key = key.Trim().ToUpper();

    int keyIndex = 0;
    int keylength = key.Length;

    for (int i = 0; i < plaintext.Length; i++)
    {
        keyIndex = keyIndex % keylength;
        int shift = (int)key[keyIndex] - 65;
        result[i] = (byte)(((int)plaintext[i] + shift) % 256);
        keyIndex++;
    }

    return result;
}
 

Deszyfrowanie:

 
public static Byte[] decryptByteVigenere(Byte[] ciphertext, string key)
{
    Byte[] result = new Byte[ciphertext.Length];

    key = key.Trim().ToUpper();

    int keyIndex = 0;
    int keylength = key.Length;

    for (int i = 0; i < ciphertext.Length; i++)
    {             
        keyIndex = keyIndex % keylength;
        int shift = (int)key[keyIndex] - 65;
        result[i]= (byte)(((int)ciphertext[i] + 256 - shift) % 256);
        keyIndex++;               
    }

    return result;
}

Generalnie wszystko rozumiem, bo całość dobrze wyjaśnia wikipedia tj.
http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher --> patrz algebraic descryption.
Jednak nie mogę zrozumieć czemu w procedurze deszyfrowania do zaszyfrowanego tekstu dodajemy wartość 256?

  (byte)(((int)ciphertext[i] + 256 - shift) % 256);

Rozumiem że przy modulo mamy 256 bo tyle mamy bajtów.

0

Te 256 to ilość wartości dla jednego bajta(0-255).

W oryginale (mod 26)

  • 26 oznacza ilość literek

W tym kodzie szyfrujesz bajty, dlatego (mod 256)

that all folks

1 użytkowników online, w tym zalogowanych: 0, gości: 1