def shift(string, key, decipher=False):
    return ''.join(
        chr((ord(c.upper())-65+key*(1-2*decipher)) % 26+65+32*c.islower())
        if c.isalpha() else c for c in string)

if __name__ == '__main__':
    assert shift('abcz+', 1) == 'bcda+', shift('abcz+', 1)
    assert shift('ABCZ+', 1) == 'BCDA+', shift('ABCZ+', 1)
    assert shift('bcda+', 1, True) == 'abcz+', shift('bcda+', 1, True)

def shift(string, key, decipher=False):
    return ''.join(
        chr((ord(c) & 224)+((ord(c) & 31)+25+key*(-2*decipher+1)*c.isalpha())
            % 26+1) for c in string)

if __name__ == '__main__':
    assert shift('abcz+', 1) == 'bcda+', shift('abcz+', 1)
    assert shift('ABCZ+', 1) == 'BCDA+', shift('ABCZ+', 1)
    assert shift('bcda+', 1, True) == 'abcz+', shift('bcda+', 1, True)

Use bitwise operators on ordinals to reduce code size
Use bitwise operators on ordinals to reduce code size

The ASCII standard neatly organizes the characters in such a way
that it is easy to manipulate and classify them using bitwise
operators.

  def shift(string, key, decipher=False):
      return ''.join(
-         chr((ord(c.upper())-65+key*(1-2*decipher)) % 26+65+32*c.islower())
-         if c.isalpha() else c for c in string)
+         chr((ord(c) & 224)+((ord(c) & 31)+25+key*(-2*decipher+1)*c.isalpha())
+             % 26+1) for c in string)
  
  if __name__ == '__main__':
      assert shift('abcz+', 1) == 'bcda+', shift('abcz+', 1)
      assert shift('ABCZ+', 1) == 'BCDA+', shift('ABCZ+', 1)
      assert shift('bcda+', 1, True) == 'abcz+', shift('bcda+', 1, True)
  
Use bitwise operators on ordinals to reduce code size
## Code Before:
def shift(string, key, decipher=False):
    return ''.join(
        chr((ord(c.upper())-65+key*(1-2*decipher)) % 26+65+32*c.islower())
        if c.isalpha() else c for c in string)

if __name__ == '__main__':
    assert shift('abcz+', 1) == 'bcda+', shift('abcz+', 1)
    assert shift('ABCZ+', 1) == 'BCDA+', shift('ABCZ+', 1)
    assert shift('bcda+', 1, True) == 'abcz+', shift('bcda+', 1, True)

## Instruction:
Use bitwise operators on ordinals to reduce code size
## Code After:
def shift(string, key, decipher=False):
    return ''.join(
        chr((ord(c) & 224)+((ord(c) & 31)+25+key*(-2*decipher+1)*c.isalpha())
            % 26+1) for c in string)

if __name__ == '__main__':
    assert shift('abcz+', 1) == 'bcda+', shift('abcz+', 1)
    assert shift('ABCZ+', 1) == 'BCDA+', shift('ABCZ+', 1)
    assert shift('bcda+', 1, True) == 'abcz+', shift('bcda+', 1, True)
