forked from HCDevelopers/MultiEncoder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
multiencoder.py
198 lines (168 loc) · 5.13 KB
/
multiencoder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env python2.7
#
# UI for the multi encoder
#
# Author: Deque
# Co-author : Psycho_Coder
# URL: https://github.com/HCDevelopers/MultiEncoder
# For license information, see LICENSE
# Encryptions
from hcdev.encryptions.zara128 import zara128
from hcdev.encryptions.vigenere import vigenere
from hcdev.encryptions.xor import xor
from hcdev.encryptions.shiftcipher import shiftcipher
from hcdev.encryptions.gronsfeld import gronsfeld
# Encodings
from hcdev.encodings.atbash import atbash
from hcdev.encodings.psychosubcipher import psychosub
from hcdev.encodings.hex import hex
from hcdev.encodings.leet import leet
from hcdev.encodings.reverse import reverse
from hcdev.encodings.binary import binary
from hcdev.encodings.morse import morse
from hcdev.encodings.b64variant import *
from hcdev.encodings.rot import *
encrypters = {
'gronsfeld': gronsfeld(),
'shiftcipher': shiftcipher,
'vigenere': vigenere(),
'xor': xor,
'zara128': zara128
}
encoders = {
'atbash': atbash,
'psychosubcipher': psychosub,
'hex': hex, 'leet': leet(),
'reverse': reverse,
'rot13': rot13,
'binary': binary,
'morse': morse,
'megan35': megan35,
'atom128': atom128,
'zong22': zong22,
'gila7': gila7,
'tripo5': tripo5,
'feron74': feron74,
'tigo3': tigo3,
'esab46': esab46,
'base64': base,
'hazz15': hazz15,
'rot18': rot18,
'rot47': rot47,
'rot5': rot5
}
abbreviations = {
'grons': 'gronsfeld',
'shift': 'shiftcipher',
'psycho': 'psychosubcipher',
'psy': 'psychosubcipher',
'vig': 'vigenere',
'rev': 'reverse',
'rot': 'rot13',
'bin': 'binary',
'megan': 'megan35',
'atom': 'atom128',
'zara': 'zara128',
'zong': 'zong22',
'base': 'base64',
'hazz': 'hazz15',
'gila': 'gila7',
'tripo': 'tripo5',
'feron': 'feron74',
'tigo': 'tigo3',
'esab': 'esab46'
}
title = """
__ __ _ _ _ ______ _
| \/ | | | | (_) ____| | |
| \ / |_ _| | |_ _| |__ _ __ ___ ___ __| | ___ _ __
| |\/| | | | | | __| | __| | "_ \ / __/ _ \ / _` |/ _ \ "__|
| | | | |_| | | |_| | |____| | | | (_| (_) | (_| | __/ |
|_| |_|\__,_|_|\__|_|______|_| |_|\___\___/ \__,_|\___|_|
Version 0.4 at Hackcommunity.com
Authors: Ex094, noize, Psycho_Coder, Deque
"""
def get_algorithms():
userargs = []
while True:
userin = raw_input('Encodings/encryptions (type "-i name" to get a description): ')
userargs = userin.split()
if len(userargs) >= 2 and userargs[0] == "-i":
print_description(userargs[1])
else:
break
return clean_list(userargs)
def print_description(algorithm):
enc = None
list = clean_list([algorithm])
if len(list) == 1:
alg = list[0]
if alg in encoders:
enc = encoders[alg]
elif alg in encrypters:
enc = encrypters[alg]
if hasattr(enc, "description"):
print "\n-----------------------------------------------------------"
print enc.description()
print "-----------------------------------------------------------"
else:
print "No description available for", alg
print("\n")
def print_algorithms():
print "Available encodings:\n",
for algo in encoders.keys():
print algo,
if hasattr(encoders[algo], "description"):
print "(-i)",
print "\n\nAvailable encryptions:\n",
for algo in encrypters.keys():
print algo,
if hasattr(encrypters[algo], "description"):
print "(-i)",
print("\n")
def en_de_code(is_decode, text, algorithms):
print
for alg in algorithms:
if alg in encoders:
encoder = encoders[alg]
function = encoder.decode if is_decode else encoder.encode
text = function(text)
if alg in encrypters:
encrypter = encrypters[alg]
key = ask_for_key(alg, encrypter)
function = encrypter.decode if is_decode else encrypter.encode
text = function(text, key)
print '>', alg + ':', text
print
print "Result:", text
def ask_for_key(algorithm, gen):
if hasattr(gen, "generate_key"):
print "Key for", algorithm, '(type "-gen" to generate):',
key = raw_input()
if key == "-gen":
key = gen.generate_key()
print "Generated key:", key
else:
print "Key for", algorithm + ':',
key = raw_input()
return key
def clean_list(dirtylist):
cleanlist = []
for element in dirtylist:
if element in abbreviations:
element = abbreviations[element]
if element in encoders or element in encrypters:
cleanlist.append(element)
else:
print
print "Couldn't find", element
return cleanlist
def main():
print title
print_algorithms()
algorithms = get_algorithms()
is_decode = True if raw_input("Encode (e) or decode (d)? ") == "d" else False
text = raw_input("Text: ")
en_de_code(is_decode, text, algorithms)
if __name__ == "__main__":
main()