Advertisement
0rx

Caesar Cipher's encryption

0rx
Jul 6th, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.90 KB | None | 0 0
  1. #########################################################################
  2. #########################################################################
  3. ###                                                   ###
  4. ###  A function to encrypt alphabetical string using Caesar Cipher's  ###
  5. ###  encryption method. It replaces the letter to the 13th letter     ###
  6. ###  next to it.                                                      ###
  7. ###  I mainly use this for fun purposes.                              ###
  8. ###                                                                   ###
  9. ###  These codes isn't originaly mine, but I changed a lot of codes   ###
  10. ###  from the original and wrap em up.                                ###
  11. ###  Use these codes as you please ;)                     ###
  12. ###                                                                   ###
  13. ###  Modified by 0rX                              ###
  14. ###                                                                   ###
  15. #########################################################################
  16. #########################################################################
  17.  
  18. def cipher(args):   ## A function to cipher letter
  19.     plaintext = args
  20.     alphabet = list('abcdefghijklmnopqrstuvwxyz')
  21.     capital_alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  22.     cipher = ''
  23.     for c in plaintext:
  24.         if c not in capital_alphabet and c not in alphabet:
  25.                     cipher += c
  26.         if c in capital_alphabet:
  27.                     cipher += capital_alphabet[(capital_alphabet.index(c)+13)%(len(capital_alphabet))]  ## You can change roll number there (change the number 13 to any number below 26)
  28.         if c in alphabet:
  29.                     cipher += alphabet[(alphabet.index(c)+13)%(len(alphabet))]    ## When you changed the roll number (originally 13) from above, you need to change the roll number (number 13 on the left) in this line to the same number as the one you wrote above
  30.     return ('Encrypted : ' + cipher)
  31.    
  32. def decipher(args):   ## A function to decipher letter
  33.     plaintext = args
  34.     alphabet = list('abcdefghijklmnopqrstuvwxyz')
  35.     capital_alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  36.     cipher = ''
  37.     for c in plaintext:
  38.         if c not in capital_alphabet and c not in alphabet:
  39.                     cipher += c
  40.         if c in capital_alphabet:
  41.                     cipher += capital_alphabet[(capital_alphabet.index(c)-13)%(len(capital_alphabet))]   ## If you change the roll number in the cipher function above, you need to change the roll number (Number 13 on the left) in this line to the same number as the one you wrote above
  42.         if c in alphabet:
  43.                     cipher += alphabet[(alphabet.index(c)-13)%(len(alphabet))]   ## When you changed the roll number (originally 13) from above, you need to change the roll number (number 13 on the left) in this line to the same number as the one you wrote above
  44.     return ('Decrypted : ' + cipher)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement