Try CoCalc Published Files Email HelpDocumentationSign In
Path: Vigenere.sage
License: none
Image: ubuntu2004
Project: Math307Attacks
Edit | Raw | Embed | Download
1
def VigenereEnc(PlainText,Key):
2
PlainText = PlainText.upper()
3
Key = Key.upper()
4
outstr = ""
5
for i in xrange(len(PlainText)):
6
plainc = PlainText[i]
7
keyc = Key[i%(len(Key)-1)]
8
plainnum = ord(plainc)-65
9
keynum = ord(keyc)-65
10
outstr += chr((plainnum+keynum)%26+65)
11
print outstr
12
13
def VigenereDec(CipherText,Key):
14
CipherText = CipherText.upper()
15
Key = Key.upper()
16
outstr = ""
17
for i in xrange(len(CipherText)):
18
cipherc = CipherText[i]
19
keyc = Key[i%(len(Key)-1)]
20
ciphernum = ord(cipherc)-65
21
keynum = ord(keyc)-65
22
outstr += chr((ciphernum-keynum)%26+65)
23
print outstr
24
25