-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcode.html
More file actions
119 lines (94 loc) · 3.06 KB
/
code.html
File metadata and controls
119 lines (94 loc) · 3.06 KB
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
<title>
ПРАКТИКА 3
</title>
</head>
<body style="background-image: url('images/backgroundBody.jpg');">
<div id = "header">
<H1>Описание второй практики</H1>
<hr>
</div>
<div id = "body">
<H1>Код Программы</H1>
<a href = "index.html">вернуться к главной</a>
<hr>
<pre>
#!/usr/bin/env python
#-*- coding: utf-8 -*-
alphabet = u'абвгдежзийклмнопрстуфхцчшщъыьэюя'
key = [0,0,0,0,0,0,0,0,0,0]
def findKey(codingString, decodingString):
codingString = codingString.lower()
decodingString = decodingString.lower()
seek = 0;
count = 0
while count < 10 and seek < len(decodingString):
if (alphabet.find(decodingString[seek]) != -1):
decodingSym = alphabet.index(decodingString[seek])
elif (decodingString[seek] == codingString[seek]):
seek += 1
continue
else:
print "ERROR: incorrect decoding string"
exit(0)
if (alphabet.find(codingString[seek]) != -1):
codingSym = alphabet.index(codingString[seek])
key[count] = codingSym - decodingSym
if key[count] < 0:
key[count] = (len(alphabet) - 1) + key[count]
count += 1
seek += 1
else:
print "ERROR: incorrect decoding string"
exit(0)
if count < 10:
print "ERROR: insufficient data"
exit(1)
def decoding(key, lines):
newStr = ""
count = 0
keyCount = 0
fileStr = ""
while count < len(lines):
newStr = ""
for sym in lines[count].decode('utf-8'):
if keyCount == 10:
keyCount = 0
if (alphabet.find(sym.lower()) != -1):
newSym = alphabet.index(sym.lower()) - key[keyCount]
if (newSym < 0):
newSym += (len(alphabet) - 1)
newSym = alphabet[newSym]
if (sym.isupper()):
newSym = newSym.upper()
newStr += newSym
keyCount += 1
else:
newStr += sym
fileStr += newStr
count += 1
return fileStr
def main(args):
pathFile = args[1].decode('utf-8')
decodingString = args[2].decode('utf-8')
lines = open(pathFile,"r").readlines()
findKey(lines[0].decode('utf-8'), decodingString)
fileStr = decoding(key, lines)
print "key: ",key
f = open( pathFile, 'w')
f.write(fileStr.encode('utf-8'))
f.close()
print "DONE"
if __name__ == '__main__':
import sys
main(sys.argv[:])
</pre>
<hr>
</div>
</body>
</html>
<div name = "code">