Vigenere Cipher

Vigenere Cipher

Elementary+
English FR RU

The Vigenère cipher is a method of encrypting alphabetic text by using a series of different Caesar ciphers based on the letters of a keyword. It is a simple form of polyalphabetic substitution.

In the Vigenère cipher each letter of a message is shifted along some number of places with different shift values. To encrypt, a table of alphabets can be used, termed a tabula recta, Vigenère square, or Vigenère table. It consists of the alphabet written out 26 times in different rows, each version of the alphabet is shifted cyclically to the left compared to the previous alphabet. At different points in the encryption process, the cipher uses a different alphabet from one of the rows. The alphabet used at each point depends on a repeating keyword.

\  A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
 \----------------------------------------------------
A| A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
B| B C D E F G H I J K L M N O P Q R S T U V W X Y Z A
C| C D E F G H I J K L M N O P Q R S T U V W X Y Z A B
D| D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
E| E F G H I J K L M N O P Q R S T U V W X Y Z A B C D
F| F G H I J K L M N O P Q R S T U V W X Y Z A B C D E
G| G H I J K L M N O P Q R S T U V W X Y Z A B C D E F
H| H I J K L M N O P Q R S T U V W X Y Z A B C D E F G
I| I J K L M N O P Q R S T U V W X Y Z A B C D E F G H
J| J K L M N O P Q R S T U V W X Y Z A B C D E F G H I
K| K L M N O P Q R S T U V W X Y Z A B C D E F G H I J
L| L M N O P Q R S T U V W X Y Z A B C D E F G H I J K
M| M N O P Q R S T U V W X Y Z A B C D E F G H I J K L
N| N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
O| O P Q R S T U V W X Y Z A B C D E F G H I J K L M N
P| P Q R S T U V W X Y Z A B C D E F G H I J K L M N O
Q| Q R S T U V W X Y Z A B C D E F G H I J K L M N O P
R| R S T U V W X Y Z A B C D E F G H I J K L M N O P Q
S| S T U V W X Y Z A B C D E F G H I J K L M N O P Q R
T| T U V W X Y Z A B C D E F G H I J K L M N O P Q R S
U| U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
V| V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
W| W X Y Z A B C D E F G H I J K L M N O P Q R S T U V
X| X Y Z A B C D E F G H I J K L M N O P Q R S T U V W
Y| Y Z A B C D E F G H I J K L M N O P Q R S T U V W X
Z| Z A B C D E F G H I J K L M N O P Q R S T U V W X Y

To see how this works, lets take, the message "DONTWORRYBEHAPPY" and the keyword "CHECKIO". Write the message and the keyword below, then shift each letter in the message related by corresponded letter in the repeating keyword.

Message:   DONTWORRYBEHAPPY
Key:       CHECKIOCHECKIOCH
Encrypted: FVRVGWFTFFGRIDRF

Vigenère can also be viewed algebraically. If the letters A–Z are taken to be the numbers 0–25, and addition is performed modulo 26, then Vigenère encryption E using the key K can be written as:
C i = E k (M i ) = (M i + K i ) % 26

Now, consider the following scenario: you and your friend use that cipher for correspondence and you've forgot the key. But, to your luck, you have an archive with encrypted and decrypted message. With that you can find the key and decrypt the new fresh message from your friend.

Input: Three arguments. An old decrypted message, an old encrypted message and a new encrypted message as strings (unicode for py2).

Output: The new decrypted message as a string.

Example:

decode_vigenere('HELLO', 'OIWWC', 'ICP') == "BYE"
    

How it is used: This is a simple cipher which had widespread usage in olden times. As we can see, the key is can be easily calculated if you know a little bit about the content of the message.

Precondition:
all(re.match("[A-Z]+\Z", text) for text in args)
len(key) ≤ len(old_encrypted)
2 * len(key) <= len(old_encrypted) < len(new_encrypted) or len(new_encrypted) <= len(old_encrypted)

45
Settings
Code:
Other:
Invalid hot key. Each hot key should be unique and valid
Hot keys:
CheckiO Extensions

CheckiO Extensions allow you to use local files to solve missions. More info in a blog post.

In order to install CheckiO client you'll need installed Python (version at least 3.8)

Install CheckiO Client first:

pip3 install checkio_client

Configure your tool

checkio --domain=py config --key=

Sync solutions into your local folder

checkio sync

(in beta testing) Launch local server so your browser can use it and sync solution between local file end extension on the fly. (doesn't work for safari)

checkio serv -d

Alternatevly, you can install Chrome extension or FF addon

checkio install-plugin
checkio install-plugin --ff
checkio install-plugin --chromium

Read more here about other functionality that the checkio client provides. Feel free to submit an issue in case of any difficulties.

Pair Programming (Beta-version)

Welcome to Pair Programming! Engage in real-time collaboration on coding projects by starting a session and sharing the provided unique URL with friends or colleagues. This feature is perfect for joint project development, debugging, or learning new skills together. Simply click 'Start Session' to begin your collaborative coding journey!

Waiting for Pair Programming to start...

You are trying to join a pair programming session that has not started yet.

Please wait for the session creator to join.

Waiting for Pair Programming to reconnect...

It looks like the creator of the pair programming session closed the editor window.

It might happen accidentally, so that you can wait for reconnection.

×
 
 
<< <
> >>
exec show

Whats Next?

Free accounts will see Best CheckiO solutions with some delay.
Best Solutions will be opened in a moment
Become Awesome and Don't wait
The next stage is ""
Will be activated in
View More Solutions Random Review Solutions Go to the next mission