caesar

package module
v0.0.0-...-ccfb4de Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2017 License: MIT Imports: 1 Imported by: 0

README

Caesar

Caesar's Cipher implementation for Go

It is not considered cryptographicaly strong algorithm! See also ROT13 algorithm

Русский

Реализация алгоритма шифрования Цезаря для языка Go.

Данный алгоритм не является надёжным! См. также алгоритм ROT13

Badges / Значки

Build Status GoDoc Go Report Card

Example / Пример


package main

import (
	"fmt"

	"github.com/vodolaz095/caesar"
)

func main() {
	cryptor := caesar.NewRussian()
	fmt.Println(cryptor.Decrypt("ИЫЛРУДХРТ", 8)) // => Будильник
}

Documentation

Overview

Package caesar is a Golang implementation of Caesar's Cipher. This algorithm has some historical interest but is not considered cryptographicaly strong It also implements ROT13 algorithm as subset of Caesar's Cipher with shift of 13. Symbols not defined in Alphabet are passed as is. See https://en.wikipedia.org/wiki/Caesar_cipher and https://en.wikipedia.org/wiki/ROT13

Русский: реализация алгоритма шифрования Цезаря для языка Go. Представляет исторический интерес, но не является криптографически стойким! Также реализует алгоритм шифрования ROT13 как подвид алгоритма шифрования Цезаря со смещением 13 для английского языка. Символы не заданные в алфавите передаются как есть.

См. https://ru.wikipedia.org/wiki/%D0%A8%D0%B8%D1%84%D1%80_%D0%A6%D0%B5%D0%B7%D0%B0%D1%80%D1%8F и https://ru.wikipedia.org/wiki/ROT13

Example
//for rot13 algorithm
cryptor := NewEnglish()
fmt.Println(cryptor.Decrypt("URYYB", 13)) // => HELLO
fmt.Println(cryptor.Encrypt("HELLO", 13)) // => URYYB

//for Russian language
cryptorR := NewRussian()
fmt.Println(cryptorR.Decrypt("ИЫЛРУДХРТ", 8)) // => БУДИЛЬНИК
fmt.Println(cryptorR.Encrypt("БУДИЛЬНИК", 8)) // => ИЫЛРУДХРТ

Index

Examples

Constants

View Source
const EnglishAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

EnglishAlphabet is a modern English language alphabet

View Source
const LatinAlphabet = "ABCDEFGHIKLMNOPQRSTVXYZ"

LatinAlphabet is a Classical Latin Alphabet

View Source
const RussianAlphabet = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"

RussianAlphabet is a modern Russian language alphabet - with Ё

Variables

This section is empty.

Functions

This section is empty.

Types

type Caesar

type Caesar struct {
	Alphabet []string
}

Caesar is a struct, holding alphabet being used, alongside with Encrypt and Decrypt functions

func New

func New(alphabet string) Caesar

New makes interface for encrypting/decrypting any alphabet consisting from manifold of UTF8 characters

func NewEnglish

func NewEnglish() Caesar

NewEnglish makes interface for encrypting/decrypting English alphabet

func NewLatin

func NewLatin() Caesar

NewLatin makes interface for encrypting/decrypting Classic Latin alphabet

func NewRussian

func NewRussian() Caesar

NewRussian makes interface for encrypting/decrypting Russian alphabet

Example
cryptor := NewRussian()
fmt.Println(cryptor.Decrypt("ИЫЛРУДХРТ", 8)) // => Будильник

func (*Caesar) Decrypt

func (c *Caesar) Decrypt(input string, shift uint) (ret string)

Decrypt works for given string with shift provided

func (*Caesar) Encrypt

func (c *Caesar) Encrypt(input string, shift uint) (ret string)

Encrypt works for given string with shift provided

Directories

Path Synopsis
example
simple command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL