Skip to content

C implementation of the Vigènere cipher and the attack on it using Kasiski examination and frequence analysis

Notifications You must be signed in to change notification settings

phillbush/vigenere

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VIGENERE(1)                 General Commands Manual                VIGENERE(1)

NAME
     vigenere, kasiski – polyalphabetic cipher encryption and attack utilities

SYNOPSIS
     vigenere [-de] key
     kasiski [-ep]

DESCRIPTION
     The vigenere utility implements encryption and decryption using the
     Vigenere polyalphabetic shift cipher on a given alphabetic key.  The
     kasiski utility implements a method of cryptanalysis of such cipher based
     on Kasiski examination and frequence analysis.

     vigenere uses the key given as argument to encrypt or decrypt the text
     read from standard input.  The result is written into standard output.
     Both the key argument and the standard input must contain plain
     alphabetic characters (ie, uppercase or lowercase latin letters) encoded
     in ASCII; any other character is ignored and is output as it is, without
     being encrypted or decrypted.

     The options for vigenere are as follows:

     -d      Perform decryption

     -e      Perform encryption (this is the default if no option is given).

     kasiski reads a ciphertext from standard input and tries to guess the key
     used to encrypt it with vigenere.  The guessed key is written into
     standard output.  The read ciphertext must have been generated by
     vigenere on either an English plaintext message or a Portuguese plaintext
     message (only the frequency of letters in those languages are known).

     The options for kasiski are as follows:

     -e      Use letter frequency in the English language for the frequency
             analysis.  (this is the default if no option is given).

     -p      Use letter frequency in the Portuguese language for the frequency
             analysis.

EXAMPLES
     Consider the following message text in the file sample.txt:

           I'd just like to interject for a moment.  What you're referring to as
           Linux, is in fact, GNU/Linux, or as I've recently taken to calling it,
           GNU plus Linux.  Linux is not an operating system unto itself, but
           rather another free component of a fully functioning GNU system made
           useful by the GNU corelibs, shell utilities and vital system components
           comprising a full OS as defined by POSIX.

           Many computer users run a modified version of the GNU system every day,
           without realizing it.  Through a peculiar turn of events, the version of
           GNU which is widely used today is often called "Linux", and many of its
           users are not aware that it is basically the GNU system, developed by
           the GNU Project.

           There really is a Linux, and these people are using it, but it is just a
           part of the system they use.  Linux is the kernel: the program in the
           system that allocates the machine's resources to the other programs that
           you run.  The kernel is an essential part of an operating system, but
           useless by itself; it can only function in the context of a complete
           operating system.  Linux is normally used in combination with the GNU
           operating system: the whole system is basically GNU with Linux added, or
           GNU/Linux.  All the so-called "Linux" distributions are really
           distributions of GNU/Linux.

     The following example encrypts the message: using the string "stallman"
     as key.

           $ <sample.txt vigenere -e stallman
           A'w jfdf lvcx tz tztrjcene roe s foxpzt.  [...]

     The following example encrypts and then decrypts the same message using
     the same key.

           $ <sample.txt vigenere -e stallman | vigenere -d stallman
           I'd just like to interject for a moment.  [...]

     The following example encrypts the same message using the same key and
     then tries to guess the key used to encrypt it.

           $ <sample.txt vigenere -e stallman | kasiski -e
           stallman

HISTORY
     The vigenere and kasiski utilities are the product of a project for 2022
     2nd semester's course of Cyber Security of the Computer Science
     department of the University of Brasilia, Brasil.

BUGS
     kasiski is not perfect.  It may not guess the key for relly short
     messages, messages with more coincidental than accidental trigram
     repetitions, messages with no trigram repetition at all, or messages with
     a letter frequency very different from the ones common in the English or
     Portuguese languages.

     Short keys may be correctly guessed, but repeated a few number of times
     (which are also valid. In the Vigenere cipher, a key is equivalent to its
     repetition).

           $ <sample.txt vigenere -e gnu | kasiski -e
           gnugnugnugnu

     Mid-size to long keys whose length is a prime number are probably guessed
     wrong:

           $ <sample.txt vigenere -e installgentoo | kasiski -e
           inwtallgentooihstaalhpntooinstallkentdoinstallgenguo

     Fiddling with the THRESHOLD value in the code can sometimes make kasiski
     guess the right key.

     kasiski also uses lots of memory.  Mostly because of its trigram
     hashtable with no collision.

AUTHORS
     Lucas de Sena ⟨lucas at seninha dot org⟩

OpenBSD 7.2                    December 9, 2022                    OpenBSD 7.2

About

C implementation of the Vigènere cipher and the attack on it using Kasiski examination and frequence analysis

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published