Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Royek Worksheet 1

50 views
#Curtis Royek #SM473 Worksheet 1 #Last modified 22 JAN 19 #Worksheet 1 Question 1 #I will iterate over the integers from 1 to 25 and check which are invertible mod 26 for i in range(1,26): if (gcd(i,26)) == 1: b = inverse_mod(i,26) print str(i) + " is invertible mod 26 and the inverse is " + str(b) else: print str(i) + " is noninvertible mod 26"
1 is invertible mod 26 and the inverse is 1 2 is noninvertible mod 26 3 is invertible mod 26 and the inverse is 9 4 is noninvertible mod 26 5 is invertible mod 26 and the inverse is 21 6 is noninvertible mod 26 7 is invertible mod 26 and the inverse is 15 8 is noninvertible mod 26 9 is invertible mod 26 and the inverse is 3 10 is noninvertible mod 26 11 is invertible mod 26 and the inverse is 19 12 is noninvertible mod 26 13 is noninvertible mod 26 14 is noninvertible mod 26 15 is invertible mod 26 and the inverse is 7 16 is noninvertible mod 26 17 is invertible mod 26 and the inverse is 23 18 is noninvertible mod 26 19 is invertible mod 26 and the inverse is 11 20 is noninvertible mod 26 21 is invertible mod 26 and the inverse is 5 22 is noninvertible mod 26 23 is invertible mod 26 and the inverse is 17 24 is noninvertible mod 26 25 is invertible mod 26 and the inverse is 25
#Worksheet 1 Question 2 #this code will produce a valid key for the affine cipher by checking that a is invertible mod 26 a=0 while gcd(a,26) != 1: a = randint(2,25) b = randint(2,25) print "(" + str(a) + "," + str(b) + ") is a valid key for the affine cipher"
(11,2) is a valid key for the affine cipher