Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 21
Image: ubuntu2004
def AffineEnc(a, b, PlainText,size=26): PlainText=PlainText.upper() if gcd(a,26)!=1: print "warning GCD of a and {0} is not 1".format(size) outstr = "" for c in PlainText: outstr+= chr(((ord(c)-65)*a+b)%size+65) print outstr
AffineEnc(9,2,"AFFINE")
CVVWPM
def AffineDec(a,b,CipherText,size=26): CipherText = CipherText.upper() if gcd(a,26)!=1: print "warning GCD of a and {0} is not 1".format(size) return ainv = inverse_mod(a,size) outstr="" for c in CipherText: outstr+= chr(((ord(c)-65-b)*ainv)%size+65) print outstr
AffineDec(3,2,"HOEH")
TEST
(11^(-1)*7)%26
3