affine

92 days ago by voloch

Examples of classical ciphers from:

http://doc.sagemath.org/html/en/reference/cryptography/sage/crypto/classical.html

S= AlphabeticStrings() S A = AffineCryptosystem(S); A 
       
Affine cryptosystem on Free alphabetic string monoid on A-Z
Affine cryptosystem on Free alphabetic string monoid on A-Z
P = A.encoding("The affine cryptosystem generalizes the shift cipher.") C = A.enciphering(1, 5, P); C 
       
YMJFKKNSJHWDUYTXDXYJRLJSJWFQNEJXYMJXMNKYHNUMJW
YMJFKKNSJHWDUYTXDXYJRLJSJWFQNEJXYMJXMNKYHNUMJW
A.deciphering(1, 5, C) 
       
THEAFFINECRYPTOSYSTEMGENERALIZESTHESHIFTCIPHER
THEAFFINECRYPTOSYSTEMGENERALIZESTHESHIFTCIPHER
D=A.enciphering(1,6,P) print D A.enciphering(1,20,D) 
       
ZNKGLLOTKIXEVZUYEYZKSMKTKXGROFKYZNKYNOLZIOVNKX
THEAFFINECRYPTOSYSTEMGENERALIZESTHESHIFTCIPHER
ZNKGLLOTKIXEVZUYEYZKSMKTKXGROFKYZNKYNOLZIOVNKX
THEAFFINECRYPTOSYSTEMGENERALIZESTHESHIFTCIPHER
A.enciphering(3,1,A.encoding("abcde")) 
       
BEHKN
BEHKN
for x in range(1,26): print A.deciphering(1,x,C) 
       
XLIEJJMRIGVCTXSWCWXIQKIRIVEPMDIWXLIWLMJXGMTLIV
WKHDIILQHFUBSWRVBVWHPJHQHUDOLCHVWKHVKLIWFLSKHU
VJGCHHKPGETARVQUAUVGOIGPGTCNKBGUVJGUJKHVEKRJGT
UIFBGGJOFDSZQUPTZTUFNHFOFSBMJAFTUIFTIJGUDJQIFS
THEAFFINECRYPTOSYSTEMGENERALIZESTHESHIFTCIPHER
SGDZEEHMDBQXOSNRXRSDLFDMDQZKHYDRSGDRGHESBHOGDQ
RFCYDDGLCAPWNRMQWQRCKECLCPYJGXCQRFCQFGDRAGNFCP
QEBXCCFKBZOVMQLPVPQBJDBKBOXIFWBPQEBPEFCQZFMEBO
PDAWBB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