-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcriptofunction_1.py
46 lines (42 loc) · 1.2 KB
/
criptofunction_1.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
def cipher(message,key,tip):
#getting chaars
with open ("cripto_chars.txt", "r") as myfile:
b = myfile.readlines()[4]
d = b.find(' ')
b1 = b.split()
alfab = ' '.join(b1)
alfab_n = int(len(alfab) - 1)
#msg var
newmsg = ''
#key
if type(key) == int or type(key) == float:
key = int(key)
else:
key,key1 = str(key),0
for i in key:
key1 = key1+ord(i)
key = key1
while key>100:
key= int(key/10)
lis = [key]*(len(message)+1)
for i in range(1,len(lis)):
if lis[i-2]%2==0:
lis[i] = 1+sum(lis[i-2:i])
if lis[i-2]%2!=0:
lis[i] = int(lis[i-2]/5)
lis = lis[1:]
#Function
for i in range(len(message)):
#function for coding
if tip == 'c':
if message[i] in alfab:
newmsg += alfab[int((alfab.find(message[i]) - lis[i])%alfab_n)]
else:
newmsg += message[i]
#Function for decoding
if tip == 'd':
if message[i] in alfab:
newmsg += alfab[int((alfab.find(message[i]) + lis[i])%alfab_n)]
else:
newmsg += message[i]
return newmsg