Giter VIP home page Giter VIP logo

vigenere-cracker's Introduction

Vigenère Cipher Cracker

Code by TomMakesThings

November 2020


What is the Vigenère Cipher?

This is a type of substitution cipher used to encrypt plaintext. The key is a word that is repeated to the length of the plaintext. Each letter is assigned a numeric value and the plaintext and key are added to obtain the ciphertext. For example if the word to encrypt is MONATHEOCTOCAT and the key is GIT, then:

Character Numeric
Plaintext MONATHEOCTOCAT M:12 O:14 N:13 A:0 T:19 H:7 E:4 O:14 C:2 T:19 O:14 C:2 A:0 T:19
Key GITGITGITGITGI G:6 I:8 T:19 G:6 I:8 T:19 G:6 I:8 T:19 G:6 I:8 T:19 G:6 I:8
Ciphertext SWGGBAKWVZWVGB S:18 W:22 G:6 G:6 B:1 A:0 K:10 W:22 V:21 Z:25 W:22 V:21 G:6 B:1

Breaking the Cipher

The Vigenère cipher is hard to crack providing a key is never reused. However, given two ciphertexts encrypted under the same key and a list of potential plaintext solutions it becomes possible to obtain the key through brute force as demonstrated in VigenereCracker.java.

Algorithm Steps:

  • Read in a text file containing a list of words
  • Read in two ciphertexts encrypted with the same key
  • Create a list of potential keys for each ciphertext
    • The ciphertext is compared to each word in the text file by calculating the difference between the numerical values of letters in the same positions.
    • Each numerical difference is converted to a character.
    • The characters are joined to form a candidate key that is added to a list.
    • For example C1: [CIHTGGMJAS, CHYUJQGWEZ, CHYJZGKAAS, CHYJZGKANS, ...] and C2: [LLKZBHITRS, LKBAERCGVZ, LKBPUHGKRS, LKBPUHGKES, ...]
  • The lists of potential keys for C1 and C2 are compared to find a match
    • If a single match is found then this must be the reused key.
    • If multiple keys are found then the original key cannot be determined. This may occur when one or both of the ciphertexts are short.
    • If no keys are found then the plaintext for one or both of the ciphertexts is not in the word list.
  • Once a key is obtained, the ciphertext can be decrypted
Ciphertext 1: CIYWCUXEEK
Ciphertext 2: LLBCXVTOVK
Length of shortest ciphertext: 10
Added list of words
Created list of possible keys for ciphertext 1
Created list of possible keys for ciphertext 2
Key found: TENLETTERS
Plaintext 1: JELLYBEANS
Plaintext 2: SHORTCAKES
  • If multiple keys are found then decryptions for each key are displayed
Ciphertext 1: CIYWC
Ciphertext 2: LLBCXVTOVK
Length of shortest ciphertext: 5
Added list of words
Created list of possible keys for ciphertext 1
Created list of possible keys for ciphertext 2

Multiple matches for key found: [ZRYRJ, WXQEK, WXQEJ, JUBWR, IRKUV, WRQKP, KUNON, JRKCW, JRQQP, JRKCK, JRQUV, LATWQ, JRKUJ, WAHLX, XANWJ, GUHJP, BRKJJ, TENLE, KXYEV, CRYUV]

Decryption for key 1: ZRYRJ
Plaintext 1: DRAFT
Likely match: DRAFTINESS
Plaintext 2: MUDLO?????
Closest matches: [MUDLOGGERS, MUDLOGGING]

Decryption for key 2: WXQEK
Plaintext 1: GLISS
Closest matches: [GLISSADERS, GLISSADING, GLISSANDOS]
Plaintext 2: POLYN?????
Likely match: POLYNOMIAL

Decryption for key 3: WXQEJ
Plaintext 1: GLIST
Closest matches: [GLISTENING, GLISTERING]
Plaintext 2: POLYO?????
Closest matches: [POLYOLEFIN, POLYOMINOS, POLYONYMIC]

...

Decryption for key 18: TENLE
Plaintext 1: JELLY
Closest matches: [JELLYBEANS, JELLYGRAPH, JELLYROLLS]
Plaintext 2: SHORT?????
Closest matches: [SHORTBOARD, SHORTBREAD, SHORTCAKES, SHORTCRUST, SHORTENERS, SHORTENING, SHORTFALLS, SHORTGOWNS, SHORTHAIRS, SHORTHANDS, SHORTHEADS, SHORTHORNS, SHORTLISTS, SHORTSTOPS, SHORTSWORD, SHORTWAVED, SHORTWAVES]

Decryption for key 19: KXYEV
Plaintext 1: SLASH
Closest matches: [SLASHFESTS, SLASHINGLY]
Plaintext 2: BODYC?????
Likely match: BODYCHECKS

Decryption for key 20: CRYUV
Plaintext 1: ARACH
Closest matches: [ARACHNIDAN, ARACHNOIDS]
Plaintext 2: JUDIC?????
Closest matches: [JUDICATION, JUDICATIVE, JUDICATORS, JUDICATORY, JUDICATURE, JUDICIALLY]

vigenere-cracker's People

Contributors

tommakesthings avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.