Giter Club home page Giter Club logo

cryptography's Introduction

Cryptography

A set of tools for breaking classical ciphers. This will include Monoalphabetic substitutions, vigenere encrpytion/decryption, string manipulation tools and more.

General-purpose Methods

removePunc(str)

Takes a string str, converts it to lowercase and strips out punctuation and spaces.

Example:

removePunc("Hello, World!");
//"helloworld"

splitString(str, n)

Takes a string str, removes punctuation and inserts a space every n letters.

Example:

splitString("Matrices are a type of data structure.", 4);
//"matr ices area type ofda tast ruct ure"

extractStrings(str, n)

Takes every n-th letter in a string str and generates a new string, then takes every (n+1)-th string, and generates another string and so on. Returns all n strings as an array of strings.

Example:

extractStrings("Apple orange pears lemons", 3);
//["alrgesms", "peaealo", "ponpren"]

cloneArr(arr)

Performs a deep clone on an array

Example:

cloneArr([1, 2, 4, 7]);
//[1, 2, 4, 7]

permuteArr(arr)

Recursively generates every permutation of an array, and returns the list of permutations as an array of arrays.

Exmaple:

permuteArray(['a', 'b', 'c']);
//[
  //["a", "b", "c"],
  //["b", "a", "c"],
  //["b", "c", "a"],
  //["a", "c", "b"],
  //["c", "a", "b"],
  //["c", "b", "a"]
//]

Cipher Encryption/Decryption Methods

caesarShift(str, type, rot)

Encrypts/decrypts (depending on type) a string str using a Caesar Shift of rot shifts. Preserves formatting.

Example:

caesarShift("Lorem ipsum dolor sit amet, consectetur adipiscing elit", "encrypt", 2);
//"Nqtgo kruwo fqnqt ukv cogv, eqpugevgvwt cfkrkuekpi gnkv"

monoSub(str, type, key)

Encrypts/decrypts a string str using a monoalphabetic substitution cipher, using alphabet key. Preserves formatting.

Example:

monoSub("Qdn fls zsk qdn bzs es qdn btts.", "decrypt", "zijknopdelmcbstughfqlmryxwav");
//"The sun and the man in the moon."

viginere(str, type, key)

Encrypts/decrypts a string str using the viginere cipher, with keyword key. Preserves formatting.

Example:

viginere("Attack the fort at noon.", "encrypt", "sword");
//"Sphrfc pvv ignh rw fkce."

playfair(str, key)

Encrypts a string str using the playfair cipher, with the grid generated by keyword key. Does not preserve formatting.

Example:

playfair("Elementary, my dear Watson.", "phone");
//"nmfupeqdtwlzfnbqvbutne"

columnarTranspose(inputStr, type, key)

Encrypts/decryption a string inputStr, using a columnar transpose. Does not preserve formatting.

Example:

columnarTranspose("applebanana", "encrypt", "cat")
//"penaalanpba"

Cipher Analysis Methods

freqAnalysis(str)

Performs a frequency analysis on a string str, returning the data as an ordered array of letter-frequencies, with greatest frequency first.

Example:

freqAnalysis("There are twenty-six letters in the English Language.");
//[["e", 20.45], ["t", 13.64], ["n", 9.09], ["a", 6.82], ["g", 6.82], ["h", 6.82], ...]

nGramAnalysis(input, len, outputNum, string)

Performs an n-gram analysis on a string str, where n = len. The number of results returned can be specified by outputNum, and if the input is a string (ie. not an array), string should be set to true.

Example:

nGramAnalysis("Journey to the centre of the earth", 2, 6, true);
//[th, 11.11], [he, 7.41], [nt: 3.7], [ec, 3.7], [ee, 3.7], [en, 3.7]

printFreqArr(arr)

Formats freqAnalysis/nGramAnalysis output arr as a string.

Example:

printFreqArr(freqAnalysis("There are twenty-six letters in the English Language."));
//"e: 20.45%, t: 13.64%, n: 9.09%, a: 6.82%, g: 6.82%, h: 6.82%, ..."

substringGaps(str, substr_length)

Searches string str for substrings of length substr_length, and returns a sorted array of all the distances between repeated substrings.

Example:

substringGaps("hesnotthemessiahhesaverynaughtboy", 3);
//[16]

determineShift(arr)

Finds the caesar shift ROT with the closest match to a frequency analysis output.

Example:

determineShift(freqAnalysis('Mrxuqhb wr wkh fhqwuh ri wkh hduwk'));
//3

solveCaesar(str)

Completely solves a Caesar shift cipher, given ciphertext only.

Example:

solveCaesar('Wklv lv zkdw zh gr khuh');
//This is what we do here

solveViginere(str)

Completely solves a Viginere cipher, given ciphertext only. More reliable on longer texts.

Example:

solveViginere("Yvutu avu tzml mm kq nidv avu i wqymccc moz jwjcmju? Pt’a hwptm jktptv, tlatca: Kocsnl ywlt yabv qm fiznbrm. Pqb azv voivbkug ww hhitltl aa kjl evvof on jwjcmju. Iub zv psv’k ca atc. Avu krp ie lzujocicnel sa maqcwye wi avu krp seiip mrwd ka, sw xq hhmrf hnl dcre uzuaasvu. Tasv csl gfw jav. Sgjacjg yeuvoiez kjht’a njlrm pqb wqcn mivu ubckvuz.");

//Would you like me to give you a formula for success? It’s quite simple, really: Double your rate of failure. You are thinking of failure as the enemy of success. But it isn’t at all. You can be discouraged by failure or you can learn from it, so go ahead and make mistakes. Make all you can. Because remember that’s where you will find success.

cryptography's People

Contributors

maximwebb avatar pika1928 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cryptography's Issues

Clean up clunky code for handling inputs

In the setup() function, and in ux_commands.js in general, we need to sort out how inputs are handled. This will mainly include removing all the nasty code for dynamically updating the HTML of buttons, and replacing it with static calls where data like "encrypt/decrypt" or the keyword are retrieved from the javascript, not submitted from the HTML.

Add UX for playfair encryption

  • Basic encryption
  • Basic decryption
  • Grid encryption (ie. manually enter in values)
  • Partial grid decryption (ie. decrypt some of the ciphertext with a partially complete grid key.

Add UX for gap length search

The gap length search just needs to be implemented with a numerical input, where the number specifies the length of the substring search.

The function you're after is in the README, under "substringGaps()"

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.