Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import getpass
- import time
- import sys
- class bin2ascii:
- def cal(self, asd):
- asd = asd.replace('0b', '')
- num = asd[::-1]
- MultOfTwo= [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072]
- value= ''
- for i in range(len(num)):
- additives = int(num[i])* int(MultOfTwo[i])
- value += str(additives) + '+'
- else:
- value += '0'
- return eval(value)
- b2a = bin2ascii()
- class crypter:
- def __passys__(self):
- pas = getpass.getpass('')
- if pas != '1':
- print'Access Denied!'
- time.sleep(2)
- sys.exit()
- else:
- pass
- def __init__(self):
- print'Please enter the passcode:'
- self.__passys__()
- while True:
- print'What do you want to do: E = Encrypt / D = Decrypt / Q = Quit'
- choice = raw_input()
- if choice.startswith('e'):
- self.encrypt()
- elif choice.startswith('d'):
- self.decrypt()
- elif choice.startswith('q'):
- sys.exit()
- else:
- print'E = Encrypt / D = Decrypt / Q = Quit'
- def encrypt(self):
- OEtext = ''
- key = raw_input('Please input the key for the Encryprion: ')
- print'please input the text you wish to encrypt:'
- PText = raw_input()
- for letter in PText:
- FakeAsciiVal = ord(letter) + int(key)
- while FakeAsciiVal > 126:
- FakeAsciiVal -= 96
- BiVal = bin(FakeAsciiVal)
- BiVal = BiVal.replace('0b', '')
- OELetter = BiVal
- OELetter = OELetter.replace('1', '\'')
- OELetter = OELetter.replace('0', ',')
- OELetter += '`'
- OEtext += OELetter
- print'Your crypter text is :', OEtext
- def decrypt(self):
- key = raw_input('Please input the key for the Decryption: ')
- print'please input the text you wish to decrypt:'
- EText = raw_input()
- EText = EText.replace('\'', '1')
- EText = EText.replace(',', '0')
- EText = EText.replace(' ', '')
- ELetter = ''
- DText = ''
- for EByte in EText:
- if EByte != '`':
- ELetter += EByte
- else:
- EWord = ELetter[:]
- b2a = bin2ascii()
- code = int(b2a.cal(EWord)) - int(key)
- while code < 32:
- code += 96
- DText += chr(code)
- EWord = ''
- ELetter = ''
- print DText
- if __name__ == '__main__':
- crypter()
- else:
- pass
Add Comment
Please, Sign In to add comment