Vigenère Autokey Cipher Helper
Description:
This is the advanced version of the Vigenère Cipher Helper kata. The following assumes that you have already completed that kata -- if you haven't done it yet, you should start there.
The basic concept is the same as in the previous kata (see the detailed explanation there). However, there is a major difference:
With the basic Vigenère Cipher, we assume the key is repeated for the length of the text. In this kata, the key is only used once, and then complemented by the decoded text. Thus every encoding and decoding is independent (still using the same key to begin with). Furthermore, the key index is only incremented if the current letter is in the provided alphabet.
Visual representation:
"password" // original key
"my secret code i want to secure" // message
"pa ssword myse c retc od eiwant" // full key used
Write a class that, when given a key and an alphabet, can be used to encode and decode from the cipher.
Examples
alphabet = 'abcdefghijklmnopqrstuvwxyz'
key = 'password'
# creates a cipher helper with each letter substituted
# by the corresponding character in the key
c = VigenereCipher(key, alphabet)
c.encode('codewars') # returns 'rovwsoiv'
c.decode('laxxhsj') # returns 'waffles'
c.encode('amazingly few discotheques provide jukeboxes')
# returns 'pmsrebxoy rev lvynmylatcwu dkvzyxi bjbswwaib'
c.decode('pmsrebxoy rev lvynmylatcwu dkvzyxi bjbswwaib')
# returns 'amazingly few discotheques provide jukeboxes'
Any character not in the alphabet should be left alone. For example (following from above):
c.encode('CODEWARS') # returns 'CODEWARS'
Similar Kata:
Stats:
Created | Jan 12, 2014 |
Published | Jan 12, 2014 |
Warriors Trained | 4931 |
Total Skips | 1797 |
Total Code Submissions | 26897 |
Total Times Completed | 1230 |
JavaScript Completions | 610 |
Python Completions | 624 |
CoffeeScript Completions | 20 |
Total Stars | 267 |
% of votes with a positive feedback rating | 76% of 217 |
Total "Very Satisfied" Votes | 141 |
Total "Somewhat Satisfied" Votes | 49 |
Total "Not Satisfied" Votes | 27 |