I cleaned up your code:
plaintext = raw_input("Enter the string ")
encrypted = ''
for index, char in enumerate(plaintext):
char_code = ord(char)
index_mod = index % 3
if index_mod == 0:
if char_code > 21:
offset = -21
else:
offset = 5
elif index_mod == 1:
if char_code > 24:
offset = -24
else:
offset = 2
else:
if char_code > 21:
offset = -20
else:
offset = 6
encrypted += chr(char_code + offset)
print encrypted
For fun, it could also be done like this:
offsets = [{True: -21, False: 5}, {True: -24, False: 2}, {True: -20, False: 6}]
upper_limits = [21, 24, 21]
plaintext = raw_input("Enter the string ")
encrypted = ''
for index, char in enumerate(plaintext):
char_code = ord(char)
index_mod = index % 3
offset = offsets[index_mod][char_code > upper_limits[index_mod]]
encrypted += chr(char_code + offset)
print encrypted
You could even have
offsets = [[5, -21], [2, -24], [6, -20]]
but it's less clear what's going on there.
However now that I see the pattern in the offsets (the second always being the first minus 26) that should be done in code:
offsets = [5, 2, 6]
upper_limits = [21, 24, 21]
plaintext = raw_input("Enter the string ")
encrypted = ''
for index, char in enumerate(plaintext):
char_code = ord(char)
index_mod = index % 3
offset = offsets[index_mod]
if char_code > upper_limits[index_mod]:
offset -= 26
encrypted += chr(char_code + offset)
print encrypted