Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import itertools
- import string
- import collections
- lowercase = collections.deque( string.ascii_lowercase + string.digits )
- # Getting the message...
- h = open('flag.enc')
- message = h.read()
- h.close()
- key = 'blaise'
- def encrypt( message, key, multipler = -1 ):
- compressed_message = message.lower()
- for punctuation in str(string.punctuation + ' '):
- compressed_message = compressed_message.replace(punctuation, '')
- cycler = itertools.cycle(key.lower())
- long_key = ''.join( [ cycler.next() for _ in range(len(compressed_message))] )
- coded = []
- for number in range(len(long_key)):
- cipher_letter = compressed_message[number]
- key_letter = long_key[number]
- key_index = string.ascii_lowercase.index(key_letter)
- cipher_index = string.ascii_lowercase.index(cipher_letter)
- lowercase = collections.deque( string.ascii_lowercase )
- lowercase.rotate( multipler * key_index )
- new_alphabet = ''.join(list(lowercase))
- new_character = new_alphabet[cipher_index]
- coded.append( new_character )
- return ''.join(coded)
- def decrypt( message, key, multipler = -1 ):
- return encrypt( message, key, 1 )
- print message
- print decrypt(message, key)
- # cryptaclysmevenindecipherablecipherscanbebroken
- # czqtulctqwn{Pvmf_Mooekatipritpf_Nixzisd_Cif_Ff_Mrwcio}
- # cryptaclysm{Even_Indecipherable_Ciphers_Can_Be_Broken}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement