CoCalc Public Filesclass_S20.sagews
Author: Susan Margulies
Views : 160
Compute Environment: Ubuntu 18.04 (Deprecated)
# shift enter "compiles"/runs code
A = AlphabeticStrings()
S = ShiftCryptosystem(A)
S
#K = randint(0,26)
K = 3
plaintext = S.encoding("Happy Friday YAY!!!")
plaintext
ciphertext = S.enciphering(K, plaintext)
ciphertext
m = S.deciphering(K, ciphertext)
m

Shift cryptosystem on Free alphabetic string monoid on A-Z HAPPYFRIDAYYAY KDSSBIULGDBBDB HAPPYFRIDAYYAY
A = AlphabeticStrings()
S = AffineCryptosystem(A)
S
a = 3; b = 13
K = (a, b)
K
plaintext = S.encoding("Let's Hang OUT!!!")
plaintext
mod(3*11 + 13, 26)
# 20 = u
ciphertext = S.enciphering(a, b, plaintext)
ciphertext
m = S.deciphering(a, b, ciphertext)
m

Affine cryptosystem on Free alphabetic string monoid on A-Z (3, 13) LETSHANGOUT 20 UZSPINAFDVS LETSHANGOUT
# if
a = 8
if a > 1:
a = a + 1
print "yes"
else:
a = a - 1
print "no"
a

yes 9
# for
for i in range(26):
print i

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# while
a = 7
while (a > 0):
a = a - 1
print a

# function declaration

6 5 4 3 2 1 0
# sample function definition
def my_shift(K, p):
return mod(p + K, 26)

my_shift(0, 3)

3
# playing around with Shor's algorithm
N = 21137
m = 20
gcd(m, N)

1
P = 1
while (power_mod(m, P, N) != 1):
P = P + 1
P
power_mod(m, P, N)

10098 1
mod( power_mod(m, int(P/2), N) + 1, N )

1840
gcd(power_mod(m, int(P/2), N) - 1, N)

919
N/919

23