Exemple #1
0
def exh(str):

	cNums = map(chr, range(65, 91));
	inv = calcInvInZ(26);

	for a in inv:
		for b in range(len(cNums)):
			print "(%i,%i) %s" % (a,b,affineCipherDecrypt(str,a,b));			
Exemple #2
0
def affineCipherDecrypt(string, a, b):

    cNums = map(chr, range(65, 91))
    n = len(cNums)

    decryptString = ""

    invElements = calcInvInZ(n)
    inv = calcInv(invElements, n)

    aInv = inv[invElements.index(a)]

    for c in string:
        decryptString += cNums[aInv * (cNums.index(c) - b) % n]

    return decryptString
def affineCipherDecrypt(string,a,b):

	cNums = map(chr, range(65, 91));
	n = len(cNums);	

	decryptString = "";

	invElements = calcInvInZ(n);
	inv = calcInv(invElements,n);
	
	aInv = inv[invElements.index(a)];

	for c in string:
		decryptString += cNums[aInv*(cNums.index(c) - b) % n]; 

	return decryptString;