01-cipher: Class '"Cipher"'

Cipher-classR Documentation

Class "Cipher"

Description

The Cipher class is used to change between different alphabets (and so behaves as a simple substitution cipher). The Cipher function creates a new object of the Cipher class.

Usage

Cipher(sampleText, split = "-", extras = c("-" = ":", "?" = "?"))
encode(cipher, text)
decode(cipher, text)

Arguments

sampleText

A character vector that contains all symbols you want to be able to transliterate. Duplicate symbols are automatically removed.

split

A single character used to split words into symbols. Defaults to a hyphen for our applications.

extras

Additional characters to be added for reverse tranlsiteration, since they may appear as the results of alignments in consensus sequences.

cipher

An object of the Cipher class.

text

A character vector of words to be transliterated.

Value

The Cipher function returns a new object of the Cipher class. The encode and decode functions return character vectors that are the same size as their input text parameters.

Objects from the Class

Objects should be defined using the Cipher constructor. You typically pass in a character vector of "words" that contain all the symbols that are contained in the text to be translated (i.e., encoded and decoded) between languages. A standard target alphabet is created along with forward and reverse transliteration rules.

Slots

forward:

A named character vector.

reverse:

A named character vector.

bytes:

The number of bytes used to encode each 'character' in the input test. Text with more than 72 unique characters use a two-byte encoding, which is enough for languages with up to 26*72 = 1872 characters.

Note

Attempting to manipulate a Cipher object using text containing NAs, missing values, or previously unknown symbols will result in an error.

Author(s)

Kevin R. Coombes <krc@silicovore.com>

Examples

motif <- "0-50-74-0-50-74-25-26-35"
alfa <- Cipher(motif)
alfa
en <-encode(alfa, motif)
en
de <- decode(alfa, en)
de

SVAlignR documentation built on Sept. 20, 2025, 3:01 p.m.

Related to 01-cipher in SVAlignR...