Skip to content

Java version of the Vigenère cipher (created in 1553), now breakable (since 1863)

License

Notifications You must be signed in to change notification settings

magnasilvar/vigenere-cipher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

 |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! ¯\_(ツ)_/¯

GitHub Release Java CI with Maven Quality Gate Status Coverage Known Vulnerabilities Follow @oliviermistral

vigenere-cipher - a Java implementation with a convenient CLI

Vignère cipher

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.

How to build the CLI

You need at least JDK 11 (OpenJDK is recommended). For Windows users, you need to set the JAVA_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 Native Image Toolchain

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.

Installation on Windows Platforms

  1. Navigate to the GraalVM Releases repository on GitHub. Select graalvm-ce-java11-windows-amd64-20.0.0.zip and download.
  2. Unzip the archive to your file system.
  3. 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:
      setx /M PATH "C:\Progra~1\Java\graalvm-ce-java11-20.0.0\bin;%PATH%"
      Note that the /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%
  4. 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:
    choco install visualstudio2017-workload-vctools
    After installation, set up the environment from the cmd prompt with this command:
    call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
    Then run native-image in that Command Prompt window.

Creating a Native Image

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 !

Running Native Images on different Windows

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.

CLI Usage

Encrypt

Default alphabet

vigenere encrypt --key=MyPrivateKey "Welcome to the Vigenère cipher !"

Will output: "Icatwhe ms dlc Hgvvvème vmzlcd !"

Custom alphabet

vigenere encrypt "Hello !" --key=key --alphabet=ehkloy

Will output: "Lekyo !"

Decrypt

Default alphabet

vigenere decrypt --key=MyPrivateKey "Icatwhe ms dlc Hgvvvème vmzlcd !"

Will output: "Welcome to the Vigenère cipher !"

Custom alphabet

vigenere decrypt "Lekyo !" --key=key --alphabet=ehkloy

Will output: "Hello !"

Version

vigenere --version

Will output: "2.0.0"

Using Aliases

Command Options

  • -h is the --help option alias.
  • -V is the --version option alias.

Subcommands

  • ec is the encrypt subcommand alias.
  • dc is the decrypt subcommand alias.

Subcommand Options

  • -k is the --key subcommand option alias.
  • -a is the --alphabet subcommand option alias.

About

Java version of the Vigenère cipher (created in 1553), now breakable (since 1863)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages