-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEX02.py
37 lines (32 loc) · 1.16 KB
/
EX02.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
def encode(message, shift):
shift %= 26
message2 = ""
for i in message:
ascii_number = ord(i)
if 65 <= ascii_number <= 90: #Täht on A-Z
if ascii_number + shift <= 90:
message2 += chr(ascii_number + shift)
else:
message2 += chr((ascii_number + shift)-26)
elif 97 <= ascii_number <= 122: #Täht on a-z
if(ascii_number + shift) <= 122:
message2 += chr(ascii_number + shift)
else:
message2 += chr((ascii_number + shift) - 26)
else: #Täht on mingi muu ASCII täht
message2 += i
return(message2)
def crack(encoded_message, phrase):
i = 26
while i != 0:
if phrase in encode(encoded_message, i):
return(encode(encoded_message, i))
break
i -= 1
if i == 0:
return None
ab bc
ab bc cd de ef fg gh hi ij jk kl lm mn no op pq qr rs st tu uv vw wx xy yz
git add ex01.py
git commit -m "blabla" ex01.py
git push origin master