CoCalc Shared Filesclass_S20.sagewsOpen in CoCalc with one click!
Author: Susan Margulies
Views : 26
# 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