-
Notifications
You must be signed in to change notification settings - Fork 0
/
vigener_cipher.py
46 lines (34 loc) · 1 KB
/
vigener_cipher.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
#-*-coding:utf8;-*-
#qpy:3
#qpy:console
'''
@Vigener's Cipher@
Comments:
You can change the array with the alphabet to your language,
and the program will work with your language.
Also, pay attention to the line with the switch, changing +/-,
you can change the program for encryption / decryption.
Author: Nazar Ponochevnyi
'''
# Alphabet (you can change)
A = ['А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я']
# Input values
text = input('\nInput text: ').upper()
key = input('\nInput key: ').upper()
# Basic processes
i = 0
result = ''
for t in text:
if A.count(t) != 0:
if i == len(key):
i = 0
sm = A.index(key[i]) + 1
pos = A.index(t) + sm #!!! Toggle (+/-) !!!
if pos >= len(A):
pos -= len(A)
result += A[pos]
i += 1
else:
result += t
# Output values
print('\nEncrypted/Decrypted text:', result)