polybius

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package polybius is encrypting method with polybius square ref: https://en.wikipedia.org/wiki/Polybius_square#Hybrid_Polybius_Playfair_Cipher

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Polybius

type Polybius struct {
	// contains filtered or unexported fields
}

Polybius is struct having size, characters, and key

func NewPolybius

func NewPolybius(key string, size int, chars string) (*Polybius, error)

NewPolybius returns a pointer to object of Polybius. If the size of "chars" is longer than "size", "chars" are truncated to "size".

Example
// initialize
const (
	plainText  = "HogeFugaPiyoSpam"
	size       = 5
	characters = "HogeF"
	key        = "abcdefghijklmnopqrstuvwxy"
)
p, err := NewPolybius(key, size, characters)
if err != nil {
	log.Fatalf("failed NewPolybius: %v", err)
}
encryptedText, err := p.Encrypt(plainText)
if err != nil {
	log.Fatalf("failed Encrypt: %v", err)
}
fmt.Printf("Encrypt=> plainText: %s, encryptedText: %s\n", plainText, encryptedText)

decryptedText, err := p.Decrypt(encryptedText)
if err != nil {
	log.Fatalf("failed Decrypt: %v", err)
}
fmt.Printf("Decrypt=> encryptedText: %s, decryptedText: %s\n", encryptedText, decryptedText)
Output:

Encrypt=> plainText: HogeFugaPiyoSpam, encryptedText: OGGFOOHFOHFHOOHHEHOEFFGFEEEHHHGG
Decrypt=> encryptedText: OGGFOOHFOHFHOOHHEHOEFFGFEEEHHHGG, decryptedText: HOGEFUGAPIYOSPAM

func (*Polybius) Decrypt

func (p *Polybius) Decrypt(text string) (string, error)

Decrypt decrypts with polybius encryption

func (*Polybius) Encrypt

func (p *Polybius) Encrypt(text string) (string, error)

Encrypt encrypts with polybius encryption

Jump to

Keyboard shortcuts

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