Added cabal setup scripts.

Modified files to work with cabal. Added main function in SolataireCipher.
master
Abhinav Sarkar 2012-08-31 00:27:08 +05:30
parent fd4ef85d22
commit 42c8b7db80
10 changed files with 102 additions and 10 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*.hi
*.o
input
bin
dist

View File

@ -8,7 +8,7 @@
{-# LANGUAGE BangPatterns #-}
module Cryptograms where
module Main where
import qualified Data.Map as M
import qualified Data.Set as S

View File

@ -46,7 +46,7 @@
Copyright 2012 Abhinav Sarkar <abhinav@abhinavsarkar.net>
-}
module EnglishNumerals where
module Main where
import qualified Data.Sequence as Seq
import Data.List (maximumBy, nub)

View File

@ -5,7 +5,7 @@
{-# LANGUAGE NoMonomorphismRestriction, RecordWildCards #-}
module GedcomParser where
module Main where
import Text.Parsec hiding (spaces, Line)
import System.IO

View File

@ -20,7 +20,7 @@
{-# LANGUAGE MultiParamTypeClasses, RecordWildCards #-}
module KnightsTravails where
module Main where
import qualified Data.Set as S
import AStar

View File

@ -15,7 +15,7 @@
{-# LANGUAGE BangPatterns #-}
module PhoneNumberWords where
module Main where
import qualified Data.Set as S
import qualified Data.Map as M

2
Setup.hs Normal file
View File

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

View File

@ -1,8 +1,11 @@
module SolataireCipher where
module Main where
import qualified Options.Applicative as Op
import Data.Char (toUpper, ord, chr)
import Data.List (unfoldr, splitAt, sort, elemIndex)
import Data.Maybe (fromJust)
import Control.Applicative ((<*>))
import Control.Monad ((>=>))
data Card = RankCard Int | JokerA | JokerB deriving (Eq)
@ -43,7 +46,7 @@ keyChar deck =
deck'' = moveCard deck' (bJokerIdx deck') 2
-- triple cut around the jokers
[i, j] = sort [(aJokerIdx deck''), (bJokerIdx deck'')]
[i, j] = sort [aJokerIdx deck'', bJokerIdx deck'']
(top, rest) = splitAt i deck''
(mid, bottom) = splitAt (j + 1 - i) rest
cards' = bottom ++ mid ++ top
@ -51,14 +54,14 @@ keyChar deck =
-- count cut using the value of the bottom card
c = cardValue (last cards')
(top', bottom') = splitAt c cards'
cards'' = (init bottom') ++ top' ++ [last cards']
cards'' = init bottom' ++ top' ++ [last cards']
-- output value
cV = cardValue (cards'' !! (cardValue . head $ cards''))
in
if cV == 53
then keyChar cards''
else (numToChar $ (if cV > 26 then cV - 26 else cV), cards'')
else (numToChar (if cV > 26 then cV - 26 else cV), cards'')
moveCard :: [a] -> Int -> Int -> [a]
moveCard lst idx move =
@ -119,3 +122,26 @@ decrypt deck encText =
ks = keyStream deck (length encText)
encTextNums = charsToNums encText
ksNums = charsToNums ks
data Command = Encrypt String | Decrypt String
optParser = Op.subparser $
Op.command "encrypt"
(Op.info
(Op.helper <*>
(Op.argument (Op.str >=> Just . Encrypt) (Op.metavar "CLEARTEXT")))
(Op.progDesc "Encrypts a cleartext"))
Op.& Op.command "decrypt"
(Op.info
(Op.helper <*>
(Op.argument (Op.str >=> Just . Decrypt) (Op.metavar "CRYPTTEXT")))
(Op.progDesc "Decrypts a crypttext"))
opts = Op.info (Op.helper <*> optParser) $
Op.progDesc "Encrypt or decrypts a string using the solataire cipher algorithm"
main = do
command <- Op.execParser opts
case command of
(Encrypt clearText) -> putStrLn $ encrypt serialDeck clearText
(Decrypt cryptText) -> putStrLn $ decrypt serialDeck cryptText

View File

@ -10,7 +10,7 @@
{-# LANGUAGE BangPatterns #-}
module TicTacToe where
module Main where
import Data.List (sort, nub, maximumBy)
import Data.List.Split (chunk)

62
rubyquiz.cabal Normal file
View File

@ -0,0 +1,62 @@
name: RubyQuiz
version: 1.0
synopsis: Solutions to RubyQuiz problems in Haskell
homepage: https://github.com/abhin4v/rubyquiz
bug-reports: https://github.com/abhin4v/rubyquiz/issues
license: BSD3
copyright: Copyright 2012 Abhinav Sarkar <abhinav@abhinavsarkar.net>
author: Abhinav Sarkar
cabal-version: >= 1.14
build-type: Simple
source-repository head
type: git
location: git@github.com:abhin4v/rubyquiz.git
executable TicTacToe
build-depends : base == 4.*,
containers == 0.4.*,
mtl == 2.1.*,
random == 1.0.*,
split == 0.1.4.*
main-is : TicTacToe.hs
default-language : Haskell2010
executable KnightsTravails
build-depends : base == 4.*,
containers == 0.4.*,
pqueue == 1.2.*
main-is : KnightsTravails.hs
default-language : Haskell2010
other-modules : AStar
executable Cryptograms
build-depends : base == 4.*,
containers == 0.4.*
main-is : Cryptograms.hs
default-language : Haskell2010
executable EnglishNumerals
build-depends : base == 4.*,
containers == 0.4.*,
split == 0.1.4.*
main-is : EnglishNumerals.hs
default-language : Haskell2010
executable GedcomParser
build-depends : base == 4.*,
parsec == 3.1.*
main-is : GedcomParser.hs
default-language : Haskell2010
executable PhoneNumberWords
build-depends : base == 4.*,
containers == 0.4.*
main-is : PhoneNumberWords.hs
default-language : Haskell2010
executable SolataireCipher
build-depends : base == 4.*,
optparse-applicative == 0.1.*
main-is : SolataireCipher.hs
default-language : Haskell2010