SHARE
TWEET

Untitled

a guest Jan 20th, 2020 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import string
  2. letters = string.ascii_lowercase
  3. numbers = string.digits
  4.  
  5.  
  6. def caesar_cipher(og, shift):
  7.     encrypted = ''
  8.     for i in og.lower():
  9.         let_index = letters.find(i)
  10.         num_index = numbers.find(i)
  11.         if let_index == -1 and num_index == -1:
  12.             encrypted = encrypted + i
  13.         else:
  14.             if let_index == -1:
  15.                 encrypted += str((num_index + shift) % 10)
  16.             else:
  17.                 new_ix = (let_index + shift) % len(letters)
  18.                 encrypted = encrypted + letters[new_ix]
  19.     return encrypted
  20.  
  21. print(caesar_cipher("abcd", -3))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top