Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import ceil
- alfcode={'.':35,'а':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}
- def shifrovka():
- '''Шифрует'''
- h=[]
- normtext,normkey,intkey = norm()
- for j in range(0,len(normkey)):
- stroka=''
- for i in range(j,len(normtext),len(normkey)):
- stroka+=normtext[i]
- h.append(stroka)
- result=''
- for i in range(0,len(intkey)):
- result+=(h[intkey.index(i)])
- print(result)
- def deshifrovka():
- '''Дешифрует'''
- a=[]
- pp=[]
- f=[]
- normtext,normkey,intkey = norm()
- ff = ceil(len(normtext)/len(normkey))
- for i in range(len(normkey)):
- a.append(normtext[ff*i:ff*(i+1)])
- d=dict.fromkeys(intkey)
- for i in range(0,len(a)):
- d[i]=a[i]
- for x,y in d.items():
- pp.append(y)
- result_1=''
- for i in range(len(pp)):
- for j in range(len(pp[0])):
- result_1+=pp[i][j]
- for i in range(0,len(pp[0])):
- stroka=''
- for j in range(i,len(result_1),len(pp[0])):
- stroka+=result_1[j]
- f.append(stroka)
- result=''
- for i in range(len(f)):
- for j in range(len(f[0])):
- result+=f[i][j]
- print(result)
- def norm():
- text=input('Введите текст(на русском): ')
- key=input('Введите ключ: ')
- lowtext=text.lower()
- lowkey=key.lower()
- key_1=''
- for i in lowkey:
- if i not in key_1:
- key_1+=i
- normtext=[]
- normkey=[]
- for j in list(lowtext):
- if j in alfcode:
- normtext+=j
- for i in list(key_1):
- if i in alfcode:
- normkey+=i
- while True:
- if len(normtext)%len(normkey)!=0:
- normtext+='.'
- continue
- else:
- break
- rualf='абвгдеёжзийклмнопрстуфхцчшщъыьэюя.'
- intkey_1=[]
- for i in list(normkey):
- intkey_1.append(rualf.index(i)+1)
- f=max(intkey_1)+1
- intkey=intkey_1.copy()
- for i in range(0,len(intkey_1)):
- intkey[intkey_1.index(min(intkey_1))]=i
- intkey_1[intkey_1.index(min(intkey_1))]=f
- return normtext,normkey,intkey
- while True:
- menu=int(input('''
- 1-зашифровать
- 2-дешифровать
- 0-выход
- '''))
- if menu==1:
- shifrovka()
- continue
- elif menu==2:
- deshifrovka()
- continue
- elif menu==0:
- break
- else:
- print('Неверный пункт меню!')
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement