CoCalc Public Filesex_classical1.sagews
Author: Susan Margulies
Views : 189
Compute Environment: Ubuntu 18.04 (Deprecated)
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 5 XTRJMFUUDXYWNSLBNYMFENSNY SOMEHAPPYSTRINGWITHAZINIT
S = AffineCryptosystem(AlphabeticStrings())
S
plaintext = S.encoding("Happy Holidays")
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 = """JMSWKAJMVDFIMFBYQILWVLNRYFUWFAJMIWLWIRWVOVMIRWVLNJGWLDVMNVXKVFMQVMISKLFJKHGJUKDWJCCJLBJQQWMUJLWRYFUWFMJIIWIMWVLUNMVAAFMBHKIIWMUNQYWLWSVDWVQVAAFMBVHJCHJDWJMWBWMQUNLVAAFMBLVAAFMBVQDNSYVDPWLIJJLQFHHJDWGFHFQJLFDKQQWLWIQVAAFMBVQDNSYVDPWLIJJLJMUNQYFHVMIMJQYFMBDJLW"""
A = AlphabeticStrings()
S = SubstitutionCryptosystem(A); #S
ciphertext = S.encoding(y)
ciphertext

dict_ctext = (ciphertext.frequency_distribution()).function()
dict_ctext

#######ABCDEFGHIJKLMNOPQRSTUVWXYZ
K = A('VPSIWCBYFTOUDMJAXLHQKGRENZ')
p = S.deciphering(K, ciphertext)
p
dict_ctext = (p.frequency_distribution()).function()
dict_ctext

JMSWKAJMVDFIMFBYQILWVLNRYFUWFAJMIWLWIRWVOVMIRWVLNJGWLDVMNVXKVFMQVMISKLFJKHGJUKDWJCCJLBJQQWMUJLWRYFUWFMJIIWIMWVLUNMVAAFMBHKIIWMUNQYWLWSVDWVQVAAFMBVHJCHJDWJMWBWMQUNLVAAFMBLVAAFMBVQDNSYVDPWLIJJLQFHHJDWGFHFQJLFDKQQWLWIQVAAFMBVQDNSYVDPWLIJJLJMUNQYFHVMIMJQYFMBDJLW {V: 0.0891472868217055, X: 0.00387596899224806, J: 0.0891472868217055, L: 0.0736434108527132, N: 0.0348837209302326, Y: 0.0310077519379845, P: 0.00775193798449612, B: 0.0348837209302326, D: 0.0465116279069767, F: 0.0736434108527132, Q: 0.0620155038759690, H: 0.0310077519379845, S: 0.0193798449612403, U: 0.0310077519379845, W: 0.104651162790698, I: 0.0581395348837209, K: 0.0271317829457364, M: 0.0930232558139535, O: 0.00387596899224806, A: 0.0465116279069767, C: 0.0116279069767442, G: 0.0116279069767442, R: 0.0155038759689922} ONCEUPONAMIDNIGHTDREARYWHILEIPONDEREDWEAKANDWEARYOVERMANYAQUAINTANDCURIOUSVOLUMEOFFORGOTTENLOREWHILEINODDEDNEARLYNAPPINGSUDDENLYTHERECAMEATAPPINGASOFSOMEONEGENTLYRAPPINGRAPPINGATMYCHAMBERDOORTISSOMEVISITORIMUTTEREDTAPPINGATMYCHAMBERDOORONLYTHISANDNOTHINGMORE {V: 0.0116279069767442, L: 0.0310077519379845, N: 0.0930232558139535, Y: 0.0348837209302326, P: 0.0465116279069767, B: 0.00775193798449612, D: 0.0581395348837209, F: 0.0116279069767442, Q: 0.00387596899224806, H: 0.0310077519379845, S: 0.0310077519379845, U: 0.0271317829457364, W: 0.0155038759689922, I: 0.0736434108527132, K: 0.00387596899224806, M: 0.0465116279069767, O: 0.0891472868217055, A: 0.0891472868217055, C: 0.0193798449612403, E: 0.104651162790698, G: 0.0348837209302326, R: 0.0736434108527132, T: 0.0620155038759690}