View difference between Paste ID: trNSzpUZ and BXtyKHnp
SHOW: | | - or go back to the newest paste.
1
import getpass
2
import time
3
import sys
4
class bin2ascii:
5
    def cal(self, asd):
6
        asd = asd.replace('0b', '')
7
        num = asd[::-1]
8
        MultOfTwo= [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072]
9
        value= ''
10
        for i in range(len(num)):
11
            additives = int(num[i])* int(MultOfTwo[i])
12
            value += str(additives) + '+'
13
        else:
14
            value += '0'
15
            return eval(value)
16
b2a = bin2ascii()
17
class crypter:
18
    def __passys__(self):
19
        pas = getpass.getpass('')
20
        if pas != '1':
21
            print'Access Denied!'
22
            time.sleep(2)
23
            sys.exit()
24
        else:
25
            pass
26
    def __init__(self):
27
        print'Please enter the passcode:'
28
        self.__passys__()
29
        while True:
30
            print'What do you want to do: E = Encrypt / D = Decrypt / Q = Quit'
31
            choice = raw_input()
32
            if choice.startswith('e'):
33
                self.encrypt()
34
            elif choice.startswith('d'):
35
                self.decrypt()
36
            elif choice.startswith('q'):
37
                sys.exit()
38
            else:
39
                print'E = Encrypt / D = Decrypt / Q = Quit'
40
    def encrypt(self):
41
        OEtext = ''
42
        key = raw_input('Please input the key for the Encryprion: ')
43
        print'please input the text you wish to encrypt:'
44
        PText = raw_input()
45
        for letter in PText:
46
            FakeAsciiVal = ord(letter) + int(key)
47
            while FakeAsciiVal > 126:
48
                FakeAsciiVal -= 96
49
            BiVal = bin(FakeAsciiVal)
50
            BiVal = BiVal.replace('0b', '')
51
            OELetter = BiVal
52
            OELetter = OELetter.replace('1', '\'')
53
            OELetter = OELetter.replace('0', ',')
54
            OELetter += '`'
55
            OEtext += OELetter
56
        print'Your crypter text is :', OEtext
57
    def decrypt(self):
58
        key = raw_input('Please input the key for the Decryption: ')
59
        print'please input the text you wish to decrypt:'
60
        EText = raw_input()
61
        EText = EText.replace('\'', '1')
62
        EText = EText.replace(',', '0')
63
        EText = EText.replace(' ', '')
64
        ELetter = ''
65
        DText = ''
66
        for EByte in EText:
67
            if EByte != '`':
68
                ELetter += EByte
69
            else:
70
                EWord = ELetter[:]
71
                b2a = bin2ascii()
72
                code = int(b2a.cal(EWord)) - int(key)
73
                while code  < 32:
74
                    code += 96
75
                DText += chr(code)
76
                EWord = ''
77
                ELetter = ''
78
        print DText
79
80
                
81
82
83
84
if __name__ == '__main__':
85
    crypter()
86
else:
87
    pass