Vigenère cipher
The Vigenère cipher is a cipher based on different series of characters or letters of the Caesar cipher, these characters forming a table, called Vigenère table, which is used as clue. The Vigenère cipher is a polyalphabetic simple substitution cipher.
The Vigenère cipher has been reinvented many times. The original method was described by Giovan Battista Belasso in his 1553 book The Cipher of Sig. Giovan Battista Belasso. However, it was later incorrectly attributed to Blaise de Vigenère, specifically in the 19th century, and For this reason it is still known as the 'Vigenère cipher'.
This encryption is known because it is easy to understand and implement, and it also seems unsolvable; This earned him the nickname the indecipherable code (le chiffre indéchiffrable, in French).
History
The first polyalphabetic cipher was the so-called Alberti cipher, created by Leon Battista Alberti around 1467. To facilitate calculations, it took advantage of a metal disc that allowed easy switching between the different alphabets available. Alberti's system only switched between alphabets after many words, and changes were indicated by writing the letter of the corresponding alphabet in the encrypted message. Later, in 1508, Johannes Trithemius, in his work Poligraphia, invented the tabula recta , which is basically the Vigenère table. Trithemius, however, only provided a system of progressive, rigid and predictable change between alphabets.
What is now known as the Vigenère cipher was originally described by Giovan Battista Belasso in his aforementioned book of 1533, who constructed the cipher based on the tabula recta of Trithemius, but added a repeating key to change each character between the different alphabets.
Blaise de Vigenère published his description of a similar but more robust autoclave cipher before the reign of Henry III of France in 1586. Later, in the 19th century, the invention of the cipher was no longer attributed to Vigenère.
The Vigenère cipher gained a reputation for being exceptionally robust. Even the writer and mathematician Charles Lutwidge Dodgson (Lewis Carroll) said that the Vigenère cipher was unbreakable in an article titled "The Alphabet Cipher" for a children's magazine. In 1917, Scientific American magazine stated that Vigenère's cipher was impossible to break. This reputation was undeserved, considering that the Kasiski method solved the cipher in the 19th century, and that some skilled cryptanalysts were occasionally able to break the cipher in the 16th century.
Throughout the 19th century, different variations on this system were proposed, but they did not significantly increase security and presented similar vulnerabilities; Among these were the following:
- Method of Auray
- Method of Beaufort
- Method of Gronsfeld
Gilbert Vernam tried to fix the cipher (creating the Vernam-Vigenère cipher in 1918), but despite his efforts, the cipher remains vulnerable to cryptanalysis.
Operation
message: P A R S V A U T B I E N U N E M S E key: L O U P L O U P L O U P L O U P L O U P L cryptogram: A O M X D K U K E P C T X J H T W S N I O
In this alphabet there are only 27 letters:
A | B | C | D | E | F | G | H | I | J | K | L | M | N | Ñ | O | P | Q | R | S | T | U | V | W | X | And | Z |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
In mathematical terms, the encryption function can be expressed as:
Where is the letter in the position to encrypt, is the character of the corresponding key they are in the same position, and It's the size of the alphabet. In this case .
To decrypt we perform the reverse operation:
When (Ci - Ki) >= 0
When (Ci - Ki) < 0
Where is the character in position i of the encrypted text, is the character of the corresponding key and the size of the alphabet.
It is observed that different letters in the ciphertext can correspond to the same letter in the plain text.
Batch code for Windows
An example to use should be saved as.cmd to run the program and see how it works.
@I off
title ENCRIPT VIGENERE- -coded by YURI
Rem This code encrypt your password to Vigenere systemRem o:: commentsetlocal enabledelayedexpansion
color 0A
Rem color 0A 0=black and A=green Light colors of the consoleset TheABC=nam a b c d e f h i k l m n o p q r s t u v w x y z
REM English system 26 Letters@set /a "cont=-1"set abc[0].Letters=Letters
set abc[0].ID=ID
set key[0]. Letters=Letters
set key[0].ID=ID
set pass[0]. Letters=Letters
set pass[0].ID=ID
set encrypt[0].Letters=Letters
set encrypt[0].ID=ID
set "strEn="(for %%v in (%TheABC%) do (set /a "cont=1+!cont!"set "abc[!cont!].Letters=%%v.set "abc[!cont!].ID=!cont!")@ECHO.
::Echo. REM Line stepsI "Key"@ECHO.
set /p key=I "Password"@ECHO.
set /p pass=:: Echo the length of TEST::call:strLen pass:: call the function strLen to lenght the stringShut up. :strLen keylen
Shut up. :strLen passlen
set /a q%passlen% * 1000 / %keylen%::echo q=%q:~0,-3%q:~-3%REM number with decimal bc the batch system its only integer systemset /a dec%q:♪3%set /a int%q:~0,-3%if %% EQU 0 (set /a Rounded%int%-1)REM its the times of repeat the key lenght like keykey n number depends of password lentghif %% NEQ 0 (set /a Rounded%int%)set "name=%key%"set "num=-1"set "chain[0]=1"REM string to char key:loopset /a "num=num+1"Shut up. set "name2=%%name:~%%1%%"if defined name2 (::echo(%name2%,%num%set [ chain%num%]=%%drip :loop)set "nametwo."%%"set "numtwo=-1"set "chaintwo[0]=1"@set /a "with=0"REM string to char password:I'm sorry.set /a "numtwo=numtwo+1"Shut up. set "name"%%nametwo:~%%1%%"if defined nameto (set /a "with=!numtwo!+1"::echo(%nameto%,%numtwo%set two chain[!con!]=%%drip :I'm sorry.)@set /a "nan=%keylen%-1"set /a "keyString[0]=1"@set /a "l=0"REM string to char passwordfor /l %%n in (0,1,%rounded%) do ( @set /a "m=0"for /l %%m in (0,1,%%) do ( set /a "l=1+!l!"set "keyString[!l!]=!chain[!%%m]!"if ! EQU %% (drip :continue)))REM for to debug the arrays::for /l %%t in (0,1,%passlen%) do (:: echo !keyString[%t]!::):continueREM save the arrays for /l %%n in (1,1,%%) do (set "key."%%n].Letters=!keyString[%%##set "pass[s]%%n]. Letters=!chaintwo[%%##)REM find ids for keyfor /l %%z in (1,1,%%) do (Shut up. :FindStrAndSetId Letters! abc id
set "key."%%z].ID=!id!")REM find ids for passfor /l %%x in (1,1,%%) do (Shut up. :FindStrAndSetId !pass[%x].Letters! abc id
set "pass[s]%%x].ID=!id!")REM find the Encrypted ids for /l %%and in (1,1,%%) do (Shut up. :module [%y].ID! !pass[%y].ID! encryptID
set "encrypt"%%y].ID=!encryptID!")@ECHO.
REM find the Encrypted Lettersfor /l %%w in (1,1,%%) do (Shut up. :findIdAndSetStr !encrypt[%w].ID! abc str
set "encrypt"%%w].Letters=!str!")REM Finally char to string Encrypted passwordfor /l %%v in (1,1,%%) do (set "strEn=!strEn! encrypt[%%v]. Letters!")REM Print the varShut up. I Encrypt=%str In%I !REM Keep your windows batch openpause REM function string lenght:strLen strVar [rtnVar]setlocal disableDelayedExpansion
set len=0
if defined %~1 for /f "delims." %%N in ('"(cmd /v:on /c echo(!%~1unknown()) do set /a "len=%%N-3"endlocal " if "%~2" neq " (set %~2=%%) else I %%Success /b
REM function find the id from the Letters:FindStrAndSetIdset abc = Inner
set "%~2=%abc%"for /L %%i in (1 1 26) do (if /I "%~1"♪"%~2[%i].Letters!" (set /a "%~3=!%~2[chuckles]%%i].ID!"drip :next)):nextSuccess /b
REM function find the Letters from id:findIdAndSetStrset abc = Inner
set "%~2=%abc%"for /L %%j in (1 1 26) do (if %~1 EQU %~2[%j].ID! (set %~3=%~2[%j].Letters!drip :next1)):next1Success /b
REM the formula to find encrypted letters:moduleset /a sum=%~1+%~2set /a mod%%% 26set /a div%sum% ♪ 1000/26REM this formulate have 2 errors when REM the sum is equal to 26 and the REM mod is 26 in english language REM the modular is zero but thisREM error can solved bc in all cases REM the Letter is and if %mod% EQU 0 ( set /a %~3%div:~0,-3%*25drip :jump)REM and z bc the module 27 mod 26 REM its to much decimals in it REM number in batch cant have REM decimal like another languagesif %% EQU 27 ( set /a %~3%div:~0,-3%*26drip :jump)set /a mult%div:♪3%*26set /a %~3%mult%/1000:jumpSuccess /b
Vulnerabilities
The main vulnerabilities of Vigenère's method derive from its regularity. When proposing a series of cyclical figures, the analyst simply has to look for a series of groups of letters that repeat periodically. By comparing the different repetitions, he can deduce the number of letters in the key, after which it is enough to separate these different alphabets and apply frequency analysis to each of those alphabets (Kasiski Method).
Another possibility would be to apply the match index to find the number of letters in the key.