Sharedex_classical1.sagewsOpen in CoCalc
Author: Susan Margulies
Views : 11
y = """KYFXLBKYPNDMYDVSJMWXPWHESDRXDBKYMXWXMEXPUPYMEXPWHKAXWNPYHPTLPDYJPYMFLWDKLCAKRLNXKIIKWVKJJXYRKWXESDRXDYKMMXMYXPWRHYPBBDYVCLMMXYRHJSXWXFPNXPJPBBDYVPCKICKNXKYXVXYJRHWPBBDYVWPBBDYVPJNHFSPNGXWMKKWJDCCKNXADCDJKWDNLJJXWXMJPBBDYVPJNHFSPNGXWMKKWKYRHJSDCPYMYKJSDYVNKWX""" A = AlphabeticStrings() S = SubstitutionCryptosystem(A); #S ciphertext = S.encodb6db-a-b-b-fff-4311-8b3e-36157137c5f4 S = ShiftCryptosystem(AlphabeticStrings()) S # this just removes characters not in the alphabet, like spaces plaintext = S.encoding("some happy string with a z in it") plaintext K = randint(0,25) K ciphertext = S.enciphering(K, plaintext) ciphertext p = S.deciphering(K, ciphertext) p
Shift cryptosystem on Free alphabetic string monoid on A-Z SOMEHAPPYSTRINGWITHAZINIT 10 CYWORKZZICDBSXQGSDRKJSXSD SOMEHAPPYSTRINGWITHAZINIT
S = AffineCryptosystem(AlphabeticStrings()) S plaintext = S.encoding("some random string for SM473B") plaintext # assign both a and b at the same time (a, b) = (7, 4) # or you can do a = 7 b = 4 ciphertext = S.enciphering(a, b, plaintext) ciphertext p = S.deciphering(a, b, ciphertext) p
Affine cryptosystem on Free alphabetic string monoid on A-Z SOMERANDOMSTRINGFORSMB AYKGTERZYKAHTIRUNYTAKL SOMERANDOMSTRINGFORSMB
y = """KYFXLBKYPNDMYDVSJMWXPWHESDRXDBKYMXWXMEXPUPYMEXPWHKAXWNPYHPTLPDYJPYMFLWDKLCAKRLNXKIIKWVKJJXYRKWXESDRXDYKMMXMYXPWRHYPBBDYVCLMMXYRHJSXWXFPNXPJPBBDYVPCKICKNXKYXVXYJRHWPBBDYVWPBBDYVPJNHFSPNGXWMKKWJDCCKNXADCDJKWDNLJJXWXMJPBBDYVPJNHFSPNGXWMKKWKYRHJSDCPYMYKJSDYVNKWX""" A = AlphabeticStrings() S = SubstitutionCryptosystem(A); #S ciphertext = S.encoding(y) #ciphertext dict_ctext = (ciphertext.frequency_distribution()).function() #dict_ctext #######ABCDEFGHIJKLMNOPQRSTUVWXYZ K = A('BPFIXCGHDTOUMYKAQWSJLVRENZ') #K = A('VPSIWCBYFTOUDMJAQLHQKGRENZ') #K = A('VPSIWCBYFTOUDMOAQLHQKGRENZ') #K = A('ABCDEFGHIJKLMNOPQRSTUVWXYZ') #len(K) d = S(K) p = d(ciphertext) p dict_ctext = (p.frequency_distribution()).function() dict_ctext