Try CoCalc Published Files Email HelpDocumentationSign In
Path: Vigenere.sagews
License: none
Image: ubuntu2004
Project: Math307Attacks
Edit | Raw | Embed | Download
# PlainText will have 0-25 # Key will take 0-25 # based off of https://en.wikipedia.org/wiki/File:Vigen%C3%A8re_square_shading.svg def VigenereEnc(PlainText,Key): PlainText = PlainText.upper() Key = Key.upper() outstr = "" for i in xrange(len(PlainText)): plainc = PlainText[i] keyc = Key[i%(len(Key))] plainnum = ord(plainc)-65 keynum = ord(keyc)-65 outstr += chr((plainnum+keynum)%26+65) print outstr
VigenereEnc("Test","Test")
MIKM
# PlainText will have 0-25 # Key will take 0-25 # based off of https://en.wikipedia.org/wiki/File:Vigen%C3%A8re_square_shading.svg def VigenereDec(CipherText,Key): CipherText = CipherText.upper() Key = Key.upper() outstr = "" for i in xrange(len(CipherText)): cipherc = CipherText[i] keyc = Key[i%(len(Key))] ciphernum = ord(cipherc)-65 keynum = ord(keyc)-65 outstr += chr((ciphernum-keynum)%26+65) print outstr
VigenereDec("MiKm","test")
TEST
gcd(1800,751)
1
a=12345 b=332 c=49 d=-1822
a*c+b*d
1