Methods encode(str)/decode(str)
of the keywordCipher
instance encode / decode input string based on previously provided alphabet and key.
Class keywordCipher
operates as follows:
- on instantiation second alphabet is generated based on provided alphabet and keyword
- to form a second alphabet:
2.1 all characters present in keyword are removed from provided alphabet
2.2 keyword is added to the beginning on the provided alphabet with removed characters; duplicate characters in keyword are ignored
3. calling encode(str)/decode(str)
alters string in the following way:
3.1 find an index of each character of the string in provided alphabet and replaces it with a character at the found index in generated alphabet for encode
, and vice versa for decode
3.2 if character in the string is not present in respective alphabet the character remains unchanged diring encode/decode
A script by V.