Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Crypto
Views: 262
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 = S.encoding("gonavy") 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 GONAVY 5 LTSFAD GONAVY
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}
A = AlphabeticStrings() A S = ShiftCryptosystem(A) S p = "Happy cats!" P = S.encoding(p) K = 8 Y = S.enciphering(K, P) Y type((Y.frequency_distribution()).function())
Free alphabetic string monoid on A-Z Shift cryptosystem on Free alphabetic string monoid on A-Z PIXXGKIBA <type 'dict'>
for i in range(1,26): for j in range(1,26): if int(mod(i*j, 26)) == 1: print('{}*{} == 1 mod 26'.format(i,j))
1*1 == 1 mod 26 3*9 == 1 mod 26 5*21 == 1 mod 26 7*15 == 1 mod 26 9*3 == 1 mod 26 11*19 == 1 mod 26 15*7 == 1 mod 26 17*23 == 1 mod 26 19*11 == 1 mod 26 21*5 == 1 mod 26 23*17 == 1 mod 26 25*25 == 1 mod 26
load('crypto_functions.sage') c = str_to_mod26("PVSZWALGCUG"); c k = str_to_mod26("WOOHOOWOOHO"); k [mod26_char(mod(c[i] - k[i], 26)) for i in range(len(c))]
[15, 21, 18, 25, 22, 0, 11, 6, 2, 20, 6] [22, 14, 14, 7, 14, 14, 22, 14, 14, 7, 14] ['T', 'H', 'E', 'S', 'I', 'M', 'P', 'S', 'O', 'N', 'S']