forked from AdrainYe/CTF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vigenere.py
97 lines (47 loc) · 1.02 KB
/
Vigenere.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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def Deal(key,pw):
pw = pw.lower()
flag = 0
lenght = len(key)
while(len(key)<len(pw)):
key = key + key[flag:flag+1]
flag = flag + 1
if flag == lenght:
flag = 0
if len(key)>len(pw):
key = key[0:len(pw)]
return key,pw
def Exp(key,pw,code):
result = ''
yArr = []
xArr = []
for kword in key:
for row in range(26):
if code[row][0] == kword:
yArr.append(row)
for pword in pw:
for col in range(26):
if code[0][col] == pword:
xArr.append(col)
for num in range(len(pw)):
result = result + code[yArr[num]][xArr[num]]
print result
print result.upper()
def Code():
code = [[] for i in range(26)]
for i in range(26):
for j in range(26):
num = 97 + i + j
if num >= 123:
num = num - 26
code[i].append(chr(num))
return code
def main():
code = Code()
key = raw_input("Input your key:")
pw = raw_input("Input your password:")
key,pw = Deal(key,pw)
Exp(key,pw,code)
if __name__ == '__main__':
main()