Python 2Python 2, 6157 bytes
E=lambda x:x[::2]+x[1(x+x)[::2]
D=lambda y:(-~len(y)/2*y)[::len(y)/2+1]
Thanks to l4m2 for 4 bytes.
E
encrypts and D
decrypts. I'm not counting the E=
and D=
for the score.
The decryption takes every n
'th character wrapping around, where n
is half the string length round up. The reason this inverts is that 2
and n
are inverses modulo the length of the string, so taking every n
th character inverts taking every 2
nd one.
If using a single function were allowed, I could do 44 bytes
def F(x,b):n=1+len(x)**b>>b;return(n*x)[::n]
The encrypts when b
is False
and decrypts when b
is True
. The expression 1+len(x)**b>>b
is equal to [2,len(x)/2+1][b]
.