GithubHelp home page GithubHelp logo

brianwmorgan / encryption-decryption-app Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3.47 MB

Decoder Ring is a live frontend application that allows a user to utilize a Caesar Shift, Polybius Square, or Substitution Cipher in order to encode or decode secret messages.

Home Page: https://encryption-decryption-app.vercel.app/

HTML 21.47% JavaScript 78.53%

encryption-decryption-app's Introduction

Decoder Ring | Encryption/Decryption App

Decoder Ring is a live frontend application that allows a user to utilize a Caesar Shift, Polybius Square, or Substitution Cipher in order to encode or decode secret messages.

Links

Live App deployed to Vercel

Technology

  • JavaScript, HTML, Bootstrap, Mocha

JS icon HTML icon Bootstrap icon Mocha icon

Installation

  1. Fork and clone this repository.
  2. Run npm install to install project dependencies.
  3. Run npm start to start the application locally.

App Features

Caesar Shift

The Caesar Shift is a type of substitution cipher originally used by Julius Caesar to protect messages of military significance. It relies on taking the alphabet and "shifting" letters to the right or left, based on the typical alphabetic order. For example, if you were to "shift" the alphabet to the left by 3, the letter "A" would become "X", the letter "E" would become "B", et cetera.

Caesar shift

When decoding the message, the number the original message was shifted by must be provided so the message can be shifted in the opposite direction.

App Screenshot

Caesar screenshot

Logic of the caesar() function

The caesar() function in the src/caesar.js file has three parameters:

  • input is a string that refers to the inputted text to be encoded or decoded.
  • shift is an integer refers to how much each letter is "shifted" by. A positive number means shifting to the right (i.e. "A" becomes "D") whereas a negative number means shifting to the left (i.e. "M" becomes "K").
  • encode is a boolean that refers to whether the app will encode or decode the message. By default, it is set to true (encode).

The following constraints and rules are in place:

  • If the shift value is not present, equal to 0, less than -25, or greater than 25, the function returns false and produces an error message.
  • Spaces in the message are maintained before and after encoding or decoding, as are other non-alphabetic symbols.
  • Encoding is case-insensitive (e.g., both "a" or "A" are encoded to the same result).
  • If a letter is shifted so that it goes "off" the alphabet (e.g. a shift of 3 on the letter "z"), it wraps around to the front of the alphabet (e.g. "z" becomes "c").

Examples

caesar("thinkful", 3); //> 'wklqnixo'
caesar("thinkful", -3); //> 'qefkhcri'
caesar("wklqnixo", 3, false); //> 'thinkful'

caesar("This is a secret message!", 8); //> 'bpqa qa i amkzmb umaaiom!'
caesar("BPQA qa I amkzmb umaaiom!", 8, false); //> 'this is a secret message!'

caesar("thinkful"); //> false
caesar("thinkful", 99); //> false
caesar("thinkful", -26); //> false    

Polybius Square

The Polybius Square is a cipher that is achieved by arranging a typical alphabet into a grid. Each letter is represented through a coordinate. Typically, it is possible to arrange the letters however you like and read off the coordinates in whatever direction you like.

1 2 3 4 5
1 A B C D E
2 F G H I/J K
3 L M N O P
4 Q R S T U
5 V W X Y Z

In this example, the grid will be arranged as above and coordinates will be read by comparing the first digit to the number on the top of the table and the second digit to that on the left. For example, in the above table, the letter "B" would be represented by the numerical pair "21".

When decoding the message, each pair of numbers is translated using the coordinates.

App Screenshot

Polybius screenshot

Logic of the polybius() function

The polybius() function in the src/polybius.js file has two parameters:

  • input is a string that refers to the inputted text to be encoded or decoded.
  • encode is a boolean that refers to whether it will encode or decode the message. By default it is set to true (encode).

The following constraints and rules are in place:

  • The function assumes that no additional symbols are included as part of the input. Only spaces and letters can be included.
  • When encoding, the output will still be a string.
  • When decoding, the number of characters in the string (excluding spaces) need to be even. Otherwise, it will return false and produce an error.
  • Spaces in the message are maintained before and after encoding or decoding.
  • Encoding is case-insensitive (e.g., both "a" or "A" are encoded to the same result).
  • The letters "I" and "J" share a space. When encoding, both letters are converted to 42, but when decoding, both letters are shown as "(i/j)".

Examples

polybius("thinkful"); //> "4432423352125413"
polybius("Hello world"); //> '3251131343 2543241341'

polybius("3251131343 2543241341", false); //> "hello world"
polybius("4432423352125413", false); //> "th(i/j)nkful
polybius("44324233521254134", false); //> false

Substitution Cipher

The Substitution Cipher requires a standard alphabet and a substitution alphabet. Letters from the standard alphabet will be transposed to the standard alphabet. This cipher requires that the recipient have the substitution alphabet. Otherwise, the recipient won't be able to decode the message.

Substitution cipher

For example, in the image above, the word "HELLO" would be translated as follows:

  • "H" becomes "R".
  • "E" becomes "M".
  • "L" becomes "W".
  • "O" becomes "L".

This would result in the code "RMWWL". To decrypt this code, you would simply take the result and transpose back from the substitution alphabet to the standard alphabet.

App Screenshot

Substitution screenshot

Logic of the substitution() function

The substitution() function in the src/substitution.js file has three parameters:

  • input is a string that refers to the inputted text to be encoded or decoded.
  • alphabet is a string that refers to substitution alphabet.
  • encode is a boolean that refers to whether it will encode or decode the message. By default, it is set to true (encode).

The following constraints and rules are in place:

  • The function assumes that no additional symbols will be included as part of the input. Only spaces and letters can be included.
  • Spaces in the message are maintained before and after encoding or decoding.
  • Encoding/decoding is case-insensitive (e.g., both "a" or "A" are encoded to the same result).
  • The alphabet parameter must be a string of exactly 26 characters. Otherwise, the function will return false and produce an error.
  • All of the characters in the alphabet parameter must be unique. Otherwise, the function will return false and produce an error.

Examples

substitution("thinkful", "xoyqmcgrukswaflnthdjpzibev"); //> 'jrufscpw'
substitution("You are an excellent spy", "xoyqmcgrukswaflnthdjpzibev"); //> 'elp xhm xf mbymwwmfj dne'
substitution("jrufscpw", "xoyqmcgrukswaflnthdjpzibev", false); //> 'thinkful'

substitution("thinkful", "short"); //> false
substitution("thinkful", "abcabcabcabcabcabcabcabcyz"); //> false

encryption-decryption-app's People

Contributors

brianwmorgan 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.