Your web-browser is very outdated, and as such, this website may not display properly. Please consider upgrading to a modern, faster and more secure browser. Click here to do so.
Mac 和 Linux的源设置都在~/.cabal/config 里面设置，文件是这样的
-- This is the configuration file for the 'cabal' command line tool.
-- The available configuration options are listed below.
-- Some of them have default values listed.
– Lines (like this one) beginning with…
A keyword transposition cipher is a method of choosing a monoalphabetic substitution with which to encode a message. The substitution alphabet is determined by choosing a keyword, arranging the remaining letters of the alphabet in columns below the letters of the keyword, and then reading back the columns in the alphabetical order of the letters of the keyword.
For instance, if one chose the keyword
SECRET, the columns generated would look like the following diagram. Note how the letters in the keyword are skipped when laying out the columns, and duplicate letters are removed from the keyword:
SECRT ABDFG HIJKL MNOPQ UVWXY Z
Since the alphabetical order of the characters in the keyword is
CERST, the columns are then read back in that order to get the substitution alphabet.
Original: ABCDE FGHIJ KLMNO PQRSTU VWXYZ Substitution: CDJOW EBINV RFKPX SAHMUZ TGLQY
So this is the Haskell code for encode and decode:
—buils a string with all charactars
build1 s = nub $ s ++ [‘A’..’Z’]
—build a list then transpose
build2 s n
| length s <= n = (s ++ map (\x -> ‘0’) [1..n - length s]) : 
| otherwise = take n s : build2 (drop n s) n
—build the cipher string
build3 ss = filter (/=’0’) xs
where xs = concat $ sort $ transpose ss
cps s = build3 $ build2 (build1 s) (length $ nub s)
decode1 b s
| b == ’ ’ = ’ ‘
| otherwise = [‘A’..’Z’] !! n where
n = fromJust $ elemIndex b (cps s)
encode1 b s
| b == ’ ’ = ’ ‘
| otherwise = (cps s) !! n where
n = fromJust $ elemIndex b [‘A’..’Z’]
encodeMessage s m = map (\x -> encode1 x s) m
decodeMessage s m = map (\x -> decode1 x s) m