Skip to main content
added 297 characters in body
Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652

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]

Try it online!

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 nth character inverts taking every 2nd 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].

Python 2, 61 bytes

 
E=lambda x:x[::2]+x[1::2]
D=lambda y:(-~len(y)/2*y)[::len(y)/2+1]

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 nth character inverts taking every 2nd 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].

Python 2, 57 bytes

 
E=lambda x:(x+x)[::2]
D=lambda y:(-~len(y)/2*y)[::len(y)/2+1]

Try it online!

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 nth character inverts taking every 2nd 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].

deleted 34 characters in body
Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652

Python 2, 61 bytes

E=lambda x:x[::2]+x[1::2]
D=lambda y:(-~len(y)/2*y)[::len(y)/2+1]

The first oneE encrypts, the second one and D decrypts. I'm not counting the E= and D= for the score. 

The idea of the decryption is to taketakes 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 multiplying the index bytaking every n reverses multiplying byth character inverts taking every 2nd one.

If Iusing a single function were allowed to combine the two functions into one, 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].

Python 2, 61 bytes

E=lambda x:x[::2]+x[1::2]
D=lambda y:(-~len(y)/2*y)[::len(y)/2+1]

The first one encrypts, the second one decrypts. I'm not counting the E= and D= for the score. The idea of the decryption is to take every n'th character wrapping around, where n half the length round up. The reason this inverts is that 2 and n are inverses modulo the length of the string, so multiplying the index by n reverses multiplying by 2.

If I were allowed to combine the two functions into one, 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].

Python 2, 61 bytes

E=lambda x:x[::2]+x[1::2]
D=lambda y:(-~len(y)/2*y)[::len(y)/2+1]

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 nth character inverts taking every 2nd 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].

deleted 1 character in body
Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652

Python 2, 61 bytes

E=lambda x:x[::2]+x[1::2]
D=lambda y:(-~len(y)/2*y)[::len(y)/2+1]

The first one encrypts, the second one decrypts. I'm not counting the E= and D= for the score. The idea of the decryption is to take every n'th character wrapping around, where n half the length round up. The reason this inverts is that 2 and n are inverses modulo the length of the string, so multiplying the index by n reverses multiplying by 2.

If I were allowed to combine the two functions into one, I could do 4544 bytes

def F(x,b):n=(lenn=1+len(x)/2)**b+1;return**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].

Python 2, 61 bytes

E=lambda x:x[::2]+x[1::2]
D=lambda y:(-~len(y)/2*y)[::len(y)/2+1]

The first one encrypts, the second one decrypts. I'm not counting the E= and D= for the score. The idea of the decryption is to take every n'th character wrapping around, where n half the length round up. The reason this inverts is that 2 and n are inverses modulo the length of the string, so multiplying the index by n reverses multiplying by 2.

If I were allowed to combine the two functions into one, I could do 45 bytes

def F(x,b):n=(len(x)/2)**b+1;return(n*x)[::n]

The encrypts when b is False and decrypts when b is True.

Python 2, 61 bytes

E=lambda x:x[::2]+x[1::2]
D=lambda y:(-~len(y)/2*y)[::len(y)/2+1]

The first one encrypts, the second one decrypts. I'm not counting the E= and D= for the score. The idea of the decryption is to take every n'th character wrapping around, where n half the length round up. The reason this inverts is that 2 and n are inverses modulo the length of the string, so multiplying the index by n reverses multiplying by 2.

If I were allowed to combine the two functions into one, 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].

added 232 characters in body
Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652
Loading
Source Link
xnor
  • 146.6k
  • 26
  • 279
  • 652
Loading