gchq/CyberChef

Vigenere encode and decode

Deltaspace42 opened this issue · 2 comments

Describe the bug
The Vigenere encode and decode are not giving the right crypted letters

To Reproduce
Steps to reproduce the behaviour or a link to the recipe / input used to cause the bug:

https://cyberchef.org/#recipe=Vigen%C3%A8re_Encode('a')&input=YQ
same problem:
https://cyberchef.org/#recipe=Vigen%C3%A8re_Decode('a')&input=YQ

Expected behaviour
a + a = b in vigenère encode
a - a = z in vigenère encode

Screenshots
image

Additional context
I had the same problem when I encoded it,
The recommendation is to shift +1 the alphebetical id when getting it
and when making the crypted index, shift -1 before the modulo.
such as:

// get key
var kId = alphabet.IndexOf(key[keyIndex]) + 1;
keyIndex++;

// get message
var letterId = alphabet.IndexOf(letter) + 1;

// encrypt message
var cryptedId = (letterId + kId -1) % alphabetSize;
crypted += alphabet[cryptedId];

Your description is incorrect, in Vigenere, a + a = a, actually any for letter # in the input and a in the key then # + a = #.

See the first column in the table https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher#/media/File:Vigen%C3%A8re_square_shading.svg

The table above seems pretty conclusive in that we're computing the correct result. Happy to reopen if more information comes to light.