print("\n# Appendix_B--SAMPLE 010: =========")

# Chap. B.1.3 Code for the light fiction books
# Decryption of the Gold-Bug ciphertext from the novel of E.A. Poe
# Usage on terminal: python appB1_sample01.py  (needs Python 3)

PA = 'ETHSONAIRDGLBVPFYMUC'
print('Plaintext alphabet PA: ', PA, ' Length of PA', len(PA))
CA = "8;4)+*56(!302'.1:9?-"
print('Ciphertext alphabet CA:', CA, ' Length of CA', len(CA))

codetableC2P = str.maketrans(CA,PA) # the strings CA and PA must have the same length

C = '''53++!305))6*;4826)4+.)4+);806*;48!8'60))85;1+(;:+*8!83(88)5*!;46
(;88*96*?;8)*+(;485);5*!2:*+(;4956*2(5*-4)8'8*;4069285);)6!8)4++;1(+9;4
8081;8:8+1;48!85;4)485!528806*81(+9;48;(88;4(+?34;48)4+;161;:188;+?;'''
P = C.translate(codetableC2P);
print('\nKidd decrypted:')
print(P)

# if str contains symbols not in the translation, they are left unchanged
intab  = "aeiou"
outtab = "12345"
trantab = str.maketrans(intab, outtab)
stri = "this is string example..AE..wow!!!"
print("\nTest substituting only lower-case vocals:", stri.translate(trantab))

#------------------------------------
# Appendix_B--SAMPLE 010: =========
# Plaintext alphabet PA:  ETHSONAIRDGLBVPFYMUC  Length of PA 20
# Ciphertext alphabet CA: 8;4)+*56(!302'.1:9?-  Length of CA 20
# 
# Kidd decrypted:
# AGOODGLASSINTHEBISHOPSHOSTELINTHEDEVILSSEATFORTYONEDEGREESANDTHI
# RTEENMINUTESNORTHEASTANDBYNORTHMAINBRANCHSEVENTHLIMBEASTSIDESHOOTFROMTH
# ELEFTEYEOFTHEDEATHSHEADABEELINEFROMTHETREETHROUGHTHESHOTFIFTYFEETOUT
# 
# Test substituting only lower-case vocals: th3s 3s str3ng 2x1mpl2..AE..w4w!!!

