I've been learning about Vigenere ciphers and then thought of another method to Encrypt and decrypt that.

This's my method to encrypt :

I have a msg : "messages from father to his son"
I have a key : "home"
And the cipher text : "tsewmkwk fxse krhtjr mv lzl gvv"

I've created the Mathematics algorithm for the encryption, but get stuck for the decription. This's what I've made fro encryption :

msg : "messages from father to his son"
key : "homemess ages fromfa th ert ohi"

So, I include the msg as part as the encryption method. And,

my problem is :

How is mathematical/cryptanalysis method for implement this procedure below ?

msg : "tsewmkwk fxse krhtjr mv lzl gvv"
key : "homemess ages fromfa th ert ohi"
to get it back to "messages from father to his son" ?

May be somebody can help me, I'm not clever enough to make an equation.


As I know, the vigenere equation basically like this :

Ci = Ek(Mi) = (Mi + Ki) mod 26

with E is the encryption and K is the key for the Encryption. And you know that the decryption from that encryption is like this :

Mi = Dk(Ci) = (Ci - Ki) mod 26

right ?

Now, I recreate the encryption using this formula :

C_i=E_k (M_i )=(∑_(i=0)^k▒(M_i+K_i ) + ∑_(i=k+1)^m▒〖(M_i+K_i))〗 mod 26

But, that's my problem is you can see my stupidity to create the equation. But I can convert the equation to the programming but not the opposite. I want to make the equation for analysis report. May be this add the unclear problem, and please don't tell me how to encrypt or decrypt that. May be a point to the basic math can enlighten me a little.


  • $\begingroup$ I've edited the questions, may be a clear question. If it isn't just tell me. $\endgroup$ – Eko Junaidi Salam Mar 2 '15 at 1:17
  • 1
    $\begingroup$ Hello Eko. I tried editing your question to texify but I don't understand what the symbol ▒ is (final equation, in the sums, after $k$). Anyway, the key $k$ is not modified during encryption/decryption; typically when you run out of characters in the key, you start over (eg. $k_i=k_{(i \mod l(k))}$, where $l(k)$ is the length of the key.) I hope this helps. $\endgroup$ – rath Mar 2 '15 at 4:59
  • $\begingroup$ Hello @rath, thanks a lot for editing my question. The symbol just a space, I write that using ms.word equation and I paste it right here. And when I ran out the key, I use character from the message itself like I write it in the question. As long as the message. $\endgroup$ – Eko Junaidi Salam Mar 2 '15 at 5:08
  • $\begingroup$ Oh I see. Does it work with $k=$ homehomehome... instead? $\endgroup$ – rath Mar 2 '15 at 5:23
  • 1
    $\begingroup$ On a tangent, the method you describe appears to be equivalent to the autokey cipher (a form of which was actually described in the writings of Blaise de Vigenère, unlike the cipher nowadays commonly bearing his name). $\endgroup$ – Ilmari Karonen Mar 3 '15 at 16:38

First, you decrypt the first four characters. The plaintext you find is the key for the next block of four characters, so after this you can decrypt the next block, finding the key for the block after that, and so on.

This means you will need a case distinction: one case for the first $|K|$ characters (where $|\dots| \stackrel{\text{def}}{=} \text{the length of $\cdots$}$), and one case for the rest of the text. Mathematically, you could write this down as follows:

$$C_i = \begin{cases}i < |K| & M_i + K_i \pmod{26}\\ i \geq |K| & M_i + M_{i - |K|} \pmod{26}\end{cases}$$

For $i<|K|$ we take the standard Vigenère formula. For the rest, you take the ciphertext one keylength back as key. Note that my formula assumes you start with $i=0$; if you start with $i=1$ you'll need $\le$ and $>$ instead.

Then, decryption is done similarly:

$$M_i = \begin{cases}i < |K| & C_i - K_i \pmod{26}\\ i \geq |K| & C_i - M_{i - |K|} \pmod{26}\end{cases}$$

  • $\begingroup$ Thanks, but it didn't point out the problem $\endgroup$ – Eko Junaidi Salam Feb 26 '15 at 7:34
  • $\begingroup$ Then your question is unclear. Try editing it to make the problem clear. $\endgroup$ – user4686 Feb 26 '15 at 7:35
  • $\begingroup$ thanks, can you explain a little bit what you mean (Mi + Ci-|K| (mod 26)) in the encryption and decryption too ? Because if your equation like that, for encryption it means after I runs out my key character I use my message for the rest of message length instead using cipher result to the rest of message length. So, the message it self is a part of the key. $\endgroup$ – Eko Junaidi Salam Mar 2 '15 at 9:08
  • $\begingroup$ @EkoJunaidiSalam you're right, I had forgotten your question a bit. $C_i$ should've been $M_i$ in two places; I edited the answer. $\endgroup$ – user4686 Mar 2 '15 at 9:20
  • $\begingroup$ It seems your equation for decrypt is not right... please take a look for the "i". The first i-k is key character. But for the next i is a msg character. So you must another variabel to index the msg from j=0 $\endgroup$ – Eko Junaidi Salam Mar 2 '15 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.