-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTrans.py
106 lines (92 loc) · 4.1 KB
/
Trans.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
banner = """\u001b[36;1m
█████▄ ██▀███ ▄▄▄ ▄████ ▒█████ ███▄ ▄███ ▄███ ▓▓▄ █
▒██ ██▌▓██ ▒ ██▒▒████▄ ██▒ ▀█▒▒██ ██▒ ██▒▀█▀█ █ ▒██ ██ ▄ ██ ▀█ █
░██ █▌▓██ ▄█ ▒▒██ ▀█▄ ▒██░▄▄▄░▒██░ ██ ▓██ ▓██▒ ██ ▀█▄▓ ██ ▀█ ██▒
░▓█▄ ▌▒██▀▀█▄ ░██▄▄▄▄██ ░▓█ ██▓▒██ ██░▒██ ▒██ ░██▄▄▄▄██ ▓██▒ ▐▌██▒
░▒████▓ ░██▓ ▒██▒ ▓█ ▓██▒░▒▓███▀▒░ ████▓▒░▒██▒ ░██▒ ▓█ ▓██▒▒██░ ▓██░
▒▒▓ ▒ ░ ▒▓ ░▒▓░ ▒▒ ▒█░ ░▒ ▒ ░ ▒░▒░▒░ ░ ▒░ ░ ░ ▒▒ ▓▒█░░ ▒░ ▒ ▒
░ ▒ ▒ ░▒ ░ ▒░ ▒ ▒▒ ░ ░ ░ ░ ▒ ▒░ ░ ░ ░ ▒ ▒▒ ░░ ░░ ░ ▒░
░ ░ ░ ░░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ▒ ░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
\u001b[32;1m
--Presented with <3 by Shivanshu Sharma
\u001b[35 ___ _ _ __ _ _ ___________ _ _ __ __ _ _ __ _
| |_)|_||\|(_ |_)/ \(_ | | | / \|\| | \|_ / / \| \|_ |_)
| | \| || |__)| \_/__)_|_ | _|_\_/| | |_/|__\__\_/|_/|__|\\
\u001b[32;1m \u001b[0m """
print(banner)
menu=""" \u001b[33;1m
------------------------------------------
LIST OF DECODERS |
------------------------------------------
[+] ASCII CONVERTER -- Ascii.py |
[+] ATBASH DECODER -- Atbash.py |
[+] CAESER DECODER -- Caeser.py |
[+] BACON DECODER -- Bacon.py |
[+] BASE32 DECODER -- Base32.py |
[+] BASE64 DECODER -- Base64.py |
[+] BASE85 DECODER -- Base85.py |
[+] DNA DECODER -- Dna.py |
[+] MORSE DECODER -- Morse.py |
[+] NUMBER SYSTEM -- Num.py |
[!] BINARY TO TEXT |
[!] HEX TO TEXT |
[!] OCTAL TO TEXT |
[+] RAILFENCE DECODER -- Rail.py |
[+] REVERSE CIPHER -- Reverse.py |
[+] ROTn DECODER -- Rot.py |
[+] TRANSPOSITION CIPHER -- Trans.py |
[+] VIGNERE DECODER -- Vignere.py |
------------------------------------------s
\u001b[32;1m"""
print(menu)
import math
def decrypt(message, keyword):
matrix = new1(ordering(keyword), message)
plaintext = "";
for r in range(len(matrix)):
for c in range (len(matrix[r])):
plaintext += matrix[r][c]
return plaintext
def new1(keySeq, message):
width = len(keySeq)
height = math.ceil(len(message) / width)
if height * width < len(message):
height += 1
matrix = new2(width, height, len(message))
pos = 0
for num in range(len(keySeq)):
column = keySeq.index(num+1)
r = 0
while (r < len(matrix)) and (len(matrix[r]) > column):
matrix[r][column] = message[pos]
r += 1
pos += 1
return matrix
def new2(width, height, length):
matrix = []
totalAdded = 0
for r in range(height):
matrix.append([])
for c in range(width):
if totalAdded >= length:
return matrix
matrix[r].append('')
totalAdded += 1
return matrix
def ordering(keyword):
sequence = []
for pos, ch in enumerate(keyword):
previousLetters = keyword[:pos]
newNumber = 1
for previousPos, previousCh in enumerate(previousLetters):
if previousCh > ch:
sequence[previousPos] += 1
else:
newNumber += 1
sequence.append(newNumber)
return sequence
cipher = input("Enter Ciphertext :")
key = input("Enter the Key :")
dec = decrypt(cipher,key)
print(dec)