Advertisement
Guest User

Untitled

a guest
Sep 12th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. #!/usr/bin/python
  2. import sys
  3. from secret import key
  4.  
  5. def encrypt(plaintext,key):
  6.     key_format = []
  7.     index = 0
  8.     ciphertext = ''
  9.     alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  10.    
  11.     for c in key:
  12.         if c.upper() in alpha:
  13.             key_format.append(alpha.index(c.upper()))
  14.  
  15.     for c in plaintext:
  16.         if c.upper() in alpha:
  17.             if c in alpha:
  18.                 if alpha.index(c) + key_format[index] > 25:
  19.                     ciphertext += alpha[alpha.index(c) + key_format[index] - 26]
  20.                 else:
  21.                     ciphertext += alpha[alpha.index(c) + key_format[index]]
  22.             else:
  23.                 if alpha.index(c.upper()) + key_format[index] > 25:
  24.                     ciphertext += alpha[alpha.index(c.upper()) + key_format[index] - 26].lower()
  25.                 else:
  26.                     ciphertext += alpha[alpha.index(c.upper()) + key_format[index]].lower()
  27.             index += 1
  28.             if index >= len(key_format):
  29.                 index = 0
  30.         else:
  31.             ciphertext += c
  32.     return ciphertext
  33.  
  34. if __name__=="__main__":
  35.     assert(len(key)==14)
  36.     with open(sys.argv[1]) as f:
  37.         plaintext = f.read()
  38.     print(encrypt(plaintext,key))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement