Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- from secret import key
- def encrypt(plaintext,key):
- key_format = []
- index = 0
- ciphertext = ''
- alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- for c in key:
- if c.upper() in alpha:
- key_format.append(alpha.index(c.upper()))
- for c in plaintext:
- if c.upper() in alpha:
- if c in alpha:
- if alpha.index(c) + key_format[index] > 25:
- ciphertext += alpha[alpha.index(c) + key_format[index] - 26]
- else:
- ciphertext += alpha[alpha.index(c) + key_format[index]]
- else:
- if alpha.index(c.upper()) + key_format[index] > 25:
- ciphertext += alpha[alpha.index(c.upper()) + key_format[index] - 26].lower()
- else:
- ciphertext += alpha[alpha.index(c.upper()) + key_format[index]].lower()
- index += 1
- if index >= len(key_format):
- index = 0
- else:
- ciphertext += c
- return ciphertext
- if __name__=="__main__":
- assert(len(key)==14)
- with open(sys.argv[1]) as f:
- plaintext = f.read()
- print(encrypt(plaintext,key))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement