Giter VIP home page Giter VIP logo

cipher's Introduction

Cipher

This package is a playground to experiment with some text ciphering. It includes a library for working with monoalphabetic ciphers as well as a command-line interface to directly use different ciphers.

Installation

Go version 1.17+

go get github.com/theovassiliou/cipher

How to use the library

import  "github.com/theovassiliou/cipher"

func main() {
    cipher := cipher.NewStdCipher(StdUppercaseAlphabet, RotateUTF8(3, StdUppercaseAlphabet))
    cleartext := "HELLO WORLD"
    encryptedText := cipher.Cipher(cleartext)
    decryptedText := cipher.Decipher(encryptedText)

    // ABCDEFGHIJKLMNOPQRSTUVWXYZ
    fmt.Println(StdUppercaseAlphabet)
    // DEFGHIJKLMNOPQRSTUVWXYZABC
    fmt.Println(RotateUTF8(3, StdUppercaseAlphabet))
    // HELLO WORLD
    fmt.Println(cleartext)
    // KHOOR ZRUOG
    fmt.Println(encryptedText)
    // HELLO WORLD
    fmt.Println(decryptedText)
}

The above example creates a standard monoalphabetic cipher and ciphers the string "HELLO WORLD" and deciphers the result.

The key alphabet is created by rotating the plaintext alphabet by 3 characters.

Command Line Tool Install

To use the ciphering via command-line build and install the command-line tool.

go install ./application/ciphertool

and make sure you have $GOPATH/bin in your $PATH

This creates an executable named ciphertool you can call directly.

$ ciphertool --help                  
chiphertool is CLI tool to cipher and decipher text using
        a set of different cipher algorithms.

Usage:
  ciphertool [command]

Available Commands:
  cipher      ciphers a text
  completion  generate the autocompletion script for the specified shell
  decipher    deciphers a ciphertext
  help        Help about any command

Flags:
  -c, --cipher string     name of the cipher and rotation. One of [reverse keyword rotation caesar] (default "rotation:3")
      --config string     config file (default is $HOME/.ciphertool.yaml)
  -f, --filename string   input filename
  -h, --help              help for ciphertool
      --raw               do not preprocess input string or keywords
  -t, --toggle            Help message for toggle

Use "ciphertool [command] --help" for more information about a command.

Usage

Cipher reads a text from stdin and ciphers or deciphers the provided text to stdout. In the case of ciphering the text is expected to be the plain text, in case of deciphering the ciphertext.

As default plain alphabet the Latin StdUppercaseAlphabet will be used, i.e. "ABCD...XYZ". Therefore a provided plain text will be first capitalized, and then encoded. The same will also be applied to any passed keyword. As a result, the ciphertext will also contain only upper-case letters.

This can be changed via options.

The following examples show how to cipher a text. The standard cipher is the "Ceasar" cipher, aka Rotate the plaintext alphabet by 3 characters.

To cipher a passed text

$ ciphertool cipher "HELLO WORLD"
KHOOR ZRUOG

To decipher a passed text

$ ciphertool decipher "KHOOR ZRUOG"
HELLO WORLD

Ciphering from stdin

Echos the string HELLO WORLD via stdin to ciphertool

echo "HELLO WORLD" | ciphertool cipher
KHOOR ZRUOG
Ciphering from file

Creates a file test.txt and ciphers the text

echo "HELLO WORLD" > test.txt && ciphertool cipher -f test.txt

Details on options for the CLI at Usage of Cipher

Features

  • Full UTF-8 support for alphabets and ciphertexts
  • Reading and writing from stdin/stdout and files

Implemented ciphers are

  • Rotation (Right and Left)
  • Caesar (default)
  • Reverse
  • Keyword

Definitions

The documentation uses the following terms and definitions

plaintext - the readable text 
ciphertext - the unreadable text
[to] cipher - the action to transform a plaintext into a ciphertext
[to] decipher - the action to transform ciphertext back to plaintext
plain alphabet - the ordered sequence of characters (or runes in go) of which the plaintext is build
key alphabet - the ordered sequence of characters (or runes in go) of which the ciphertext is build

Outlook

As this project is a finger exercise occassionally we will extend the functionality.

Most importantently I would like to add support for polyalphabetic ciphers,both in the library and in the CLI.

Other ideas are to add a more user-interactive CLI that also supports a user to decipher a given ciphertext. No, I do not think that we will suport "breaking" ciphers, but to offer some support. How this could look like I do not know yet.

An additional idea is to expose the functionality also as a web-service via a REST API. Most probably this will be made available in a seperate repo.

History and Motivation

Motivated by an audio play ("Die Drei Frageezeichen - Folge 213 Der Fluch der Medusa") I wanted to experiment with ciphering and deciphering as a finger exercise in golang.

cipher's People

Contributors

theovassiliou avatar

Watchers

James Cloos avatar  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.