-
Notifications
You must be signed in to change notification settings - Fork 0
/
VIGENERE_CIPHER.py
66 lines (61 loc) · 2.31 KB
/
VIGENERE_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import sys
import time
import os
import clipboard
class Vigenere_Cipher:
def __init__(self, SPEED, LANGUAGE, k=None):
self.key = k
self.speed = SPEED
self.language = LANGUAGE
def encrypt(self, plaintext):
cipher = ["_"] * len(plaintext)
k = str(self.key)
print("Encrypt with k = " + k)
print("#" * (len(plaintext) + 17))
print("#" + " " *(len(plaintext) + 15) +"#")
print("# PLAIN TEXT: "+plaintext+" #")
print("#" + " " *(len(plaintext) + 15) +"#")
for i in range(len(plaintext)):
cipher[i] = self.language[(self.language.index(plaintext[i]) + self.language.index(self.key[i % len(self.key)])) % len(self.language)]
text_s = "".join(cipher)
text_s = "# CIPHER TEXT: "+text_s + " #"
print('\r{}'.format(text_s), end='')
time.sleep(self.speed/len(plaintext))
print()
print("#" + " " *(len(plaintext) + 15) +"#")
print("#" * (len(plaintext) + 17))
input()
clipboard.copy("".join(cipher))
return text_s
def decrypt(self, ciphertext):
plain = ["_"] * len(ciphertext)
k = str(self.key)
print("Decrypt with k = " + k)
print("#" * (len(ciphertext) + 17))
print("#" + " " *(len(ciphertext) + 15) +"#")
print("# CIPHER TEXT: "+ciphertext+" #")
print("#" + " " *(len(ciphertext) + 15) +"#")
for i in range(len(ciphertext)):
plain[i] = self.language[(self.language.index(ciphertext[i]) - self.language.index(self.key[i % len(self.key)])) % len(self.language)]
text = "".join(plain)
text = "# PLAIN TEXT: "+text + " #"
print('\r{}'.format(text), end='')
time.sleep(self.speed/len(ciphertext))
print()
print("#" + " " *(len(ciphertext) + 15) +"#")
print("#" * (len(ciphertext) + 17))
input()
clipboard.copy("".join(plain))
return text
def do(self):
crypt = input("Decrypt or Encrypt (De/En): ")
crypt = crypt.split(" ")
crypt = "".join(crypt)
text = input(crypt + "crypt: ")
k = input("Key: ")
self.key = k
os.system('cls')
if(crypt == "De"):
self.decrypt(text)
else:
self.encrypt(text)