# Introduction 

Digital Cypher assigns to each letter of the alphabet unique number. For example:

```
 a  b  c  d  e  f  g  h  i  j  k  l  m
 1  2  3  4  5  6  7  8  9 10 11 12 13
 n  o  p  q  r  s  t  u  v  w  x  y  z
14 15 16 17 18 19 20 21 22 23 24 25 26
```

Instead of letters in encrypted word we write the corresponding number, eg. The word scout:

```
 s  c  o  u  t
19  3 15 21 20
```
Then we add to each obtained digit consecutive digits from the key. For example. In case of key equal to `1939` :

```
   s  c  o  u  t
  19  3 15 21 20
 + 1  9  3  9  1
 ---------------
  20 12 18 30 21
  
   m  a  s  t  e  r  p  i  e  c  e
  13  1 19 20  5 18 16  9  5  3  5
+  1  9  3  9  1  9  3  9  1  9  3
  --------------------------------
  14 10 22 29  6 27 19 18  6  12 8
```

# Task

Write a function that accepts an array of integers `code` and a `key` number. As the result, it should return string containg a decoded message from the `code`.

# Input / Output

The `code` is a array of positive integers.
The `key` input is a positive integer.

# Example

``` javascript
decode([ 20, 12, 18, 30, 21],1939);  ==> "scout"
decode([ 14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8],1939);  ==>  "masterpiece"
```

# Digital cypher series
- [Digital cypher vol 1](https://www.codewars.com/kata/592e830e043b99888600002d)
- [Digital cypher vol 2](https://www.codewars.com/kata/592edfda5be407b9640000b2)
- [Digital cypher vol 3 - missing key](https://www.codewars.com/kata/5930d8a4b8c2d9e11500002a)

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def decode(code, key):
	

Solutions:
from itertools import cycle
from string import ascii_lowercase

def decode(code, key):
	keys = cycle(map(int, str(key)))
	return ''.join((ascii_lowercase[n - next(keys) - 1] for n in code))


def decode(code, key):
	key = str(key)
	return ''.join([chr(code[i] + 96 - int(key[i % len(key)])) for i in range(0, len(code))])


decode = lambda c, k: ''.join((chr(a - int(b) + 96) for (a, b) in zip(c, str(k) * 30)))


def decode(code, key):
	base_dict = {}
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	for i in range(1, 27):
		base_dict[i] = alpha[i - 1]
	key_extended = []
	count = 0
	for i in range(len(code)):
		try:
			key_extended.append(int(str(key)[count]))
		except IndexError:
			count = 0
			key_extended.append(int(str(key)[count]))
		count += 1
	key_applied = []
	for i in range(len(code)):
		key_applied.append(code[i] - key_extended[i])
	decrypt = ''
	for elt in key_applied:
		decrypt += base_dict[elt]
	return decrypt


def decode(code, key):
	k = [int(k) for k in str(key)]
	n = len(k)
	return ''.join((chr(c - k[i % n] + 96) for (i, c) in enumerate(code)))


from itertools import cycle
from operator import sub

def decode(code, key):
	key = cycle(list(map(int, str(key))))
	message = list(map(sub, code, key))
	return ''.join([chr(x + ord('a') - 1) for x in message])


def decode(code, key):
	k = str(key)
	while len(k) < len(code):
		k *= 2
	return ''.join((chr(x - int(y) + 96) for (x, y) in zip(code, k)))


import itertools

def decode(code, key):
	return ''.join((chr(96 + i - int(j)) for (i, j) in zip(code, itertools.cycle(str(key)))))


from itertools import cycle

def decode(code, key):
	k = cycle(list(map(int, str(key))))
	return ''.join((chr(96 + c - next(k)) for c in code))