Advertisement
makispaiktis

Caesar's Cipher

Mar 7th, 2021 (edited)
1,154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. def convert(message, offset):
  2.     alphabet = "abcdefghijklmnopqrstuvwxyz"
  3.     result =""
  4.     for i in range(len(message)):
  5.         index = -1000
  6.         for j in range(len(alphabet)):
  7.             if message[i].lower() == alphabet[j]:
  8.                 index = j
  9.                
  10.         if index == -1000:
  11.             result += message[i]    
  12.         else:
  13.             newIndex = index + offset
  14.             if message[i] == message[i].lower():
  15.                 result += alphabet[newIndex % len(alphabet)]
  16.             else:
  17.                 result += alphabet[newIndex % len(alphabet)].upper()
  18.     return result
  19.  
  20. print(convert("HelloOOO WORLDdd", -26))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement