|A|B|C|E Still using the Vigenère square? Really?
-+-+-+-+ It's now over with the 'Vigenère cipher CLI'!
A|B|C|D \(ᵔᵕᵔ)/
-+-+-+ 🤔
B|C|C For the others, don't say we didn't warn you! ¯\_(ツ)_/¯
A little bit of history (extract from wikipedia): the Vigenère cipher is a method of encrypting alphabetic text by using a series of interwoven Caesar ciphers, based on the letters of a keyword. It employs a form of polyalphabetic substitution.
First described by Giovan Battista Bellaso in 1553, the cipher is easy to understand and implement, but it resisted all attempts to break it until 1863, three centuries later. This earned it the description le chiffre indéchiffrable (French for 'the indecipherable cipher'). Many people have tried to implement encryption schemes that are essentially Vigenère ciphers. In 1863, Friedrich Kasiski was the first to publish a general method of deciphering Vigenère ciphers.
In the 19th century the scheme was misattributed to Blaise de Vigenère (1523–1596), and so acquired its present name.
You need at least
JDK 11
(OpenJDK is recommended). For Windows users, you need to set theJAVA_HOME
environment variable.
Clone or download the vigenere-cipher project.
Package it with maven
:
mvn clean package -U
Picocli is used to provide the CLI. Thanks to the maven-shade-plugin
, this external dependency is included in the packaged JAR.
You can directly run the compiled JAR with the java -jar
command.
Example:
java -jar target\vigenere-cipher-2.0.0.jar encrypt --key=MyPrivateKey "Welcome to the Vigenère cipher !"
Will output: "Icatwhe ms dlc Hgvvvème vmzlcd !
"
GraalVM provides a great tool: "Native Image" which allows us to generate an executable for our CLI. A maven plugin (native-image-maven-plugin
) exists but it's not really convenient on Windows.
This InfoQ article Build Great Native CLI Apps in Java with Graalvm and Picocli provides details on setting up the GraalVM toolchain for creating native images. It pays special attention to Windows, where setting up the compiler toolchain can be tricky.
- Navigate to the GraalVM Releases repository on GitHub. Select graalvm-ce-java11-windows-amd64-20.0.0.zip and download.
- Unzip the archive to your file system.
- Configure
PATH
environment variable. Setting environment variables via the command line will work the same way for Windows 7, 8 and 10.- Add the GraalVM bin folder to the
PATH
environment variable:Note that thesetx /M PATH "C:\Progra~1\Java\graalvm-ce-java11-20.0.0\bin;%PATH%"
/M
flag, equivalent to-m
, requires elevated user privileges. - Restart Command Prompt to reload the environment variables. Then use the following command to check whether the variable was set correctly:
echo %PATH%
- Add the GraalVM bin folder to the
- To build native images using the Java 11 version of GraalVM (19.3.0 and greater), you can install the Visual C Build Tools Workload for Visual Studio 2017 Build Tools using chocolatey:
After installation, set up the environment from the cmd prompt with this command:
choco install visualstudio2017-workload-vctools
Then runcall "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
native-image
in that Command Prompt window.
native-image -jar target\vigenere-cipher-2.0.0.jar vigenere
Add vigenere.exe
parent folder to PATH
environment variable. That's all ! You can now use Vigenère cipher CLI everywhere you want on your computer !
The native binary we just created works fine on the machine where we just built it, but when you run it on a different Windows machine, you may have an error which reports that the VCRUNTIME140.dll
is missing.
This dll (from Microsoft Visual C++ 2015 Redistributable Update 3 RC) can be placed in the same directory as the exe, or in C:\Windows\System32
.
vigenere encrypt --key=MyPrivateKey "Welcome to the Vigenère cipher !"
Will output: "Icatwhe ms dlc Hgvvvème vmzlcd !
"
vigenere encrypt "Hello !" --key=key --alphabet=ehkloy
Will output: "Lekyo !
"
vigenere decrypt --key=MyPrivateKey "Icatwhe ms dlc Hgvvvème vmzlcd !"
Will output: "Welcome to the Vigenère cipher !
"
vigenere decrypt "Lekyo !" --key=key --alphabet=ehkloy
Will output: "Hello !
"
vigenere --version
Will output: "2.0.0
"
-h
is the--help
option alias.-V
is the--version
option alias.
ec
is theencrypt
subcommand alias.dc
is thedecrypt
subcommand alias.
-k
is the--key
subcommand option alias.-a
is the--alphabet
subcommand option alias.