Package 'cryptography'

Title: Encrypts and Decrypts Text Ciphers
Description: Playfair, Four-Square, Scytale, Columnar Transposition and Autokey methods. Further explanation on methods of classical cryptography can be found at Wikipedia; (<https://en.wikipedia.org/wiki/Classical_cipher>).
Authors: Piaras Fahey [aut, cre, cph]
Maintainer: Piaras Fahey <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0
Built: 2025-02-14 04:26:47 UTC
Source: https://github.com/piarasfahey/cryptography

Help Index


Autokey Cipher

Description

This can be used to encrypt or decrypt an Autokey cipher. The Autokey Cipher is derived from the Vigenere Cipher, in which the key and plaintext are bound to generate a new encryption key for the Vigenere method. This Vigenere method uses only letters and numbers, as such any other characters used as inputs are not used in the cipher.

Usage

autokey(message, key, encrypt = TRUE)

Arguments

message

A character vector of plaintext to be encrypted or ciphertext to be decrypted

key

A character vector to be used as the encryption key

encrypt

(Default: TRUE) TRUE will encrypt the message, while FALSE will decrypt the message.

Value

A character vector of either plaintext that has been encrypted or ciphertext that has been decrypted.

Examples

autokey("VerySecretMessage", "Hack", encrypt = TRUE)
autokey("c4JYn8JfwNoLMbmAM", "Hack", encrypt = FALSE)
autokey("Very $%^&SecretMes(*sagĀ£$%e", "Hack", encrypt = TRUE)

Columnar Transposition Cipher

Description

This can be used to encrypt or decrypt a Columnar Transposition cipher. This method is a development of the Scytale cipher that rearranges the encryption matrix used in the Scytale method by the alphabetical ordering of the encryption key.

Usage

columnar_transposition(message, key, encrypt = TRUE)

Arguments

message

A character vector

key

A character vector composed only of a-zA-Z letters used as the encryption key

encrypt

(Default: TRUE) TRUE will encrypt the message, while FALSE will decrypt the message.

Value

A character vector of either plaintext that has been encrypted or ciphertext that has been decrypted using the columnar transposition cryptographic method.

Examples

columnar_transposition("Hidden message", "hack", encrypt = TRUE)
columnar_transposition("insed sHeegdma", "hack", encrypt = FALSE)

Four-Square Cipher

Description

This can be used to encrypt or decrypt a Four-Square cipher. The Four-Square cipher is a polygraphic substitution cipher that maps digrams of text to two encryption matrices through their position in a square alphabet matrix.

Usage

four_square(message, key1, key2, encrypt = TRUE)

Arguments

message

a character vector used as the plaintext to be encrypted or the ciphertext to be decrypted

key1

a character vector used as the encryption key for the first encryption matrix

key2

a character vector used as the encryption key for the second encryption matrix

encrypt

(Default: TRUE) TRUE will encrypt the message, while FALSE will decrypt the message.

Value

A character vector of either plaintext that has been encrypted or ciphertext that has been decrypted.

Examples

four_square("THEPRISONERSHAVEESCAPED", "HACK", "SAFE", encrypt = TRUE)
four_square("SHBOTDTMPFSQDFZSCUHFPBCY", "HACK", "SAFE", encrypt = FALSE)

Playfair Cipher

Description

This can be used to encrypt or decrypt a Playfair cipher. A Playfair cipher is a polygraphic substitution cipher that maps digrams of text to other elements of an encryption matrix which is generated by a keyword.

Usage

playfair(message, key, encrypt = TRUE)

Arguments

message

a character vector to be encrypted or decrypted

key

a character vector to be used as the encryption key

encrypt

(Default: TRUE) TRUE will encrypt the message, while FALSE will decrypt the message.

Value

A character vector of either plaintext that has been encrypted or ciphertext that has been decrypted.

Examples

playfair("SUPERSECRETMESSAGE", "safety", encrypt = TRUE)
playfair("YSQFNTFDQTGRTAAFDT", "safety", encrypt = FALSE)
playfair("$%^Att&(a09Ck___He86re", "safety", encrypt = TRUE)
playfair("FSSFKPLSQT", "safety", encrypt = FALSE)

Scytale cipher

Description

This can be used to encrypt and decrypt a Scytale cipher. A Scytale cipher is an ancient form of cryptography that wraps a message (typically written on a long thing piece of paper) around a device to create a matrix with a fixed number of columns that transposes the text.

Usage

scytale(message, col, encrypt = TRUE)

Arguments

message

A character vector

col

A positive integer, this determines the number of columns in the encryption matrix. 1 column will have no effect

encrypt

(Default: TRUE) TRUE will encrypt the message, while FALSE will decrypt the message.

Value

A character vector of either plaintext that has been encrypted or ciphertext that has been decrypted.

Examples

scytale("very super secret message!", col = 4, encrypt = TRUE)
scytale("v eetseesrc s!ru rmaypseeg", col = 4, encrypt = FALSE)