import string
import numpy as np
from numpy import random
## true text
text = "Libor has already sprinted ahead of the rates indicated by central bank policies, an acceleration that has baffled economists and traders. That widening gap has alarmed those who watch it as a signal of stress in the financial system. Others have pinned it on a series of technical factors, such as rising short-term debt sales by the U.S. government and new corporate tax policies. Other markets that can be tapped for dollars including through the swaps market and liquidity lines maintained by global central banks arent yet showing a big dollar squeeze"
text
'Libor has already sprinted ahead of the rates indicated by central bank policies, an acceleration that has baffled economists and traders. That widening gap has alarmed those who watch it as a signal of stress in the financial system. Others have pinned it on a series of technical factors, such as rising short-term debt sales by the U.S. government and new corporate tax policies. Other markets that can be tapped for dollars including through the swaps market and liquidity lines maintained by global central banks arent yet showing a big dollar squeeze'
## get rid of all text except a-z (lowercase) and space
text = text.lower()
text = text.replace(".","")
text = text.replace("-","")
text = text.replace(",","")
text = "".join(list(filter(lambda x: x in letters, text))) ## remove all non letters
text
'libor has already sprinted ahead of the rates indicated by central bank policies an acceleration that has baffled economists and traders that widening gap has alarmed those who watch it as a signal of stress in the financial system others have pinned it on a series of technical factors such as rising shortterm debt sales by the us government and new corporate tax policies other markets that can be tapped for dollars including through the swaps market and liquidity lines maintained by global central banks arent yet showing a big dollar squeeze'
## make a copy of letters and shuffle
## if we don't make a copy, python with shuffle both a and letters
random.seed(689)
letters = list(string.ascii_lowercase)
letters = letters + [' ']
letters_mix = letters.copy()
random.shuffle(letters_mix)
letters_mix
['e', 'r', 'x', 'g', ' ', 'u', 'q', 'd', 'p', 'a', 'z', 'm', 'k', 't', 'b', 'h', 'i', 'o', 'w', 'l', 'n', 's', 'j', 'v', 'f', 'c', 'y']
cipher = dict(list(zip(letters,letters_mix)))
cipher
{' ': 'y', 'a': 'e', 'b': 'r', 'c': 'x', 'd': 'g', 'e': ' ', 'f': 'u', 'g': 'q', 'h': 'd', 'i': 'p', 'j': 'a', 'k': 'z', 'l': 'm', 'm': 'k', 'n': 't', 'o': 'b', 'p': 'h', 'q': 'i', 'r': 'o', 's': 'w', 't': 'l', 'u': 'n', 'v': 's', 'w': 'j', 'x': 'v', 'y': 'f', 'z': 'c'}
out = list(map(lambda x: cipher[x], text))
code = "".join(out)
code
'mprboydewyemo egfywhoptl gyed egybuyld yoel wyptgpxel gyrfyx tloemyretzyhbmpxp wyetyexx m oelpbtyldelydewyreuum gy xbtbkpwlwyetgyloeg owyldelyjpg tptqyqehydewyemeok gyldbw yjdbyjelxdyplyewyeywpqtemybuywlo wwyptyld yuptetxpemywfwl kybld owydes yhptt gyplybtyeyw op wybuyl xdtpxemyuexlbowywnxdyewyopwptqywdboll okyg rlywem wyrfyld ynwyqbs otk tlyetgyt jyxbohboel ylevyhbmpxp wybld oykeoz lwyldelyxetyr ylehh gyuboygbmmeowyptxmngptqyldobnqdyld ywjehwykeoz lyetgympinpgplfympt wykeptlept gyrfyqmbremyx tloemyretzwyeo tlyf lywdbjptqyeyrpqygbmmeoywin c '
This coded message is used in bayes_cipherP.ipynb
.