这是indexloc提供的服务,不要输入任何密码
Skip to content

MazzyK/Vigenere-Cypher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Vigenere-Cypher

A Java programme that uses the Vigenere (Vigenère) Cypher (or Cipher) to encrypt or decrypt a message.

The main elements are:

key: a key chosen by the user

message: the message to be encrypted or decrypted

cypher: a string of letters which have replaced the original letters of the message

The encryption/decryption happens with the use of a matrix referred to as the Tabula Recta. This matrix contains 26 rows of letters. Each row contains all letters of the alphabet with the first row containing the alphabet starting with the letter A and each subsequent row shifted cyclically to the left thus containing all possible 26 Caesar ciphers.

Tabula Recta

ABCDEFGHIJKLMNOPQRSTUVWXYZ
BCDEFGHIJKLMNOPQRSTUVWXYZA
CDEFGHIJKLMNOPQRSTUVWXYZAB
DEFGHIJKLMNOPQRSTUVWXYZABC
EFGHIJKLMNOPQRSTUVWXYZABCD
FGHIJKLMNOPQRSTUVWXYZABCDE
GHIJKLMNOPQRSTUVWXYZABCDEF
HIJKLMNOPQRSTUVWXYZABCDEFG
IJKLMNOPQRSTUVWXYZABCDEFGH
JKLMNOPQRSTUVWXYZABCDEFGHI
KLMNOPQRSTUVWXYZABCDEFGHIJ
LMNOPQRSTUVWXYZABCDEFGHIJK
MNOPQRSTUVWXYZABCDEFGHIJKL
NOPQRSTUVWXYZABCDEFGHIJKLM
OPQRSTUVWXYZABCDEFGHIJKLMN
PQRSTUVWXYZABCDEFGHIJKLMNO
QRSTUVWXYZABCDEFGHIJKLMNOP
RSTUVWXYZABCDEFGHIJKLMNOPQ
STUVWXYZABCDEFGHIJKLMNOPQR
TUVWXYZABCDEFGHIJKLMNOPQRS
UVWXYZABCDEFGHIJKLMNOPQRST
VWXYZABCDEFGHIJKLMNOPQRSTU
WXYZABCDEFGHIJKLMNOPQRSTUV
XYZABCDEFGHIJKLMNOPQRSTUVW
YZABCDEFGHIJKLMNOPQRSTUVWX
ZABCDEFGHIJKLMNOPQRSTUVWXY

For example if the user inputs the following:

key: ORAK
message: AVONISEVIL (spaces are not used in the message)

to encode the message the key must first be repeated to the length of the message. The message (AVONISEVIL) is 10 characters long and the key (ORAK) is 4 characters long so it will become ORAKORAKOR. In the event that the message is shorter than the key then only the number of letters required will be used to encrypt the message.

Next using the key, message and the tabula recta the letter at the intersection of the each key and message letter is identified to create the cypher. So the intersection of O (ORAKORAKOR) and A (AVONISEVIL) points to the letter O and so this is the first letter of the cypher. The whole itteration goes as follows:

KEYMESSAGEINTERSECTION LETTER
ORAKORAKORAVONISEVILO
ORAKORAKORAVONISEVILM
ORAKORAKORAVONISEVILO
ORAKORAKORAVONISEVILX
ORAKORAKORAVONISEVILW
ORAKORAKORAVONISEVILJ
ORAKORAKORAVONISEVILE
ORAKORAKORAVONISEVILF
ORAKORAKORAVONISEVILW
ORAKORAKORAVONISEVILC

Therefore the cypher is: OMOXWJEFWC

If instead we have the key and the cypher and wish to decode the cypher to get the message then we use the Tabula Recta again starting with the row where the letter of the key is located first and then we move across the row to find the relevant letter of the cypher, this is the intersection with the y axis pointing to the relevant letter of the decyphered message.

Future Work

The programme could be modified to read in the message from a file and output the message to a file. Error checks on user input with relevant messages could also be implemented.

FAQ

  • Isn't there a simpler way to code this?. In short, yes. There's probably many different/easier/harder ways to code this, this is my take on it.
  • Isn't it cipher and not cypher? The answer, as far as I can tell, is that both spellings are correct with cypher being British English.
  • Who (or what) are Orak and Avon? If you like vintage sci-fi TV shows you're in for a treat. Search for Blake's 7.

About

A Java programme that uses the Vigenere Cypher (or Cipher) to encrypt or decrypt a message.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages