Commit d7ec7dc7 authored by Vicente Parra Hurtado's avatar Vicente Parra Hurtado

Alpha 0.2

parents aaba6e98 e71267ca
# Changelog for CrypText
## Alpha 0.2
Corrected bug special character (Data.Text.Encoding)
Creating the application KeyGen with more functions
File crypt -> soon
## Alpha 0.1.3.
Creates 128/256 bytes files automatically (Depending on the length of the text).
......
......@@ -4,7 +4,11 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
<<<<<<< HEAD
-- hash: 561c6a397823960b35f6a93efab2b91411637d7afe0a7514da4c0519bad81a1a
=======
-- hash: e22a32b5a05eab746db788bfba70c4c8ad582e414c038a44d577ecb429a54f91
>>>>>>> Alpha2
name: CrypText
version: 0.1.0.0
......@@ -74,6 +78,26 @@ executable CrypTextGUI-exe
, cryptonite
, random
, text
<<<<<<< HEAD
=======
default-language: Haskell2010
executable KeyGen-exe
main-is: Main.hs
other-modules:
Paths_CrypText
hs-source-dirs:
KeyGen
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
CrypText
, base >=4.7 && <5
, base64-bytestring
, bytestring
, cryptonite
, random
, text
>>>>>>> Alpha2
default-language: Haskell2010
test-suite CrypText-test
......
Ph7Pf7BOPx+zPXsfbEp24dEczPeWVSVLnWh+/4hb1kIp9AUEgHhhyIM5UatjWQQ1SJ2osGvOn3VU+gUUOrrThloKf1dhee4wQA4CCUodKFe6Jz45c/uRU3wiKfljqUgA+XbgQFx0i3GePCtU95Z5fqqGxqmn+NgEh8Wqhm+0xEqdqOVrabn2ZdI4Yk/vaCYrfsqQ/2uJ1E0kS5nl4EuGbnlSfQ0g6UcGXSevcrNRkiQFq0CoWQifEqxxmfZl6/Je43IGt980H3jthuVWVm2D6zMYXvRJd4njNVEnCOVPye9niMOkwrpkujxEon6Wj7hQI2LKyqNXCO7gZRhVLL74Uw==
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
File added
# RoadMap
1 Cipher 256 bytes
1 Cipher 256 bytes -- OK
2 Wiki implementation
......
<<<<<<< HEAD
import NukeBull (stringtoWord8,word8toString,randomBytesString,passwordRows,passwordCols,orderLv3,orderLv3Inv,encryptAES256,decryptAES256)
=======
import NukeBull
>>>>>>> Alpha2
import EncrypText
import System.Environment
......@@ -9,6 +13,12 @@ import Data.Either
import Data.Maybe
import System.Random
import qualified Data.Text as T
import qualified Data.Text.Encoding as E
import qualified Data.Text.IO as TIO
import Crypto.Cipher.AES (AES256)
import Crypto.Cipher.Types (BlockCipher(..), Cipher(..),IV, makeIV)
import Crypto.Error (throwCryptoError)
......@@ -73,6 +83,7 @@ main = do
-- Text to crypt
putStrLn "Text to Encrypt ( Maximum number of characters: 255 ) (ASCII 217 ┘ Forbidden)"
<<<<<<< HEAD
putStrLn " ñ -> ~ ; áéíóú -> aeiou"
line1 <- getLine
......@@ -93,6 +104,24 @@ main = do
-- Need line <---> ByteString
let lineString = B.pack $ stringtoWord8 line
texto <- encryptext g bock password vectorIV lineString
=======
--line1 <- getLine
textoOn <- TIO.getLine
-- The 217 ASCII is the end of the text ( Point Control)
--let line = line1 ++ [chr(217)]
g <- getStdGen
g <- newStdGen
--- No more 256 bytes
if T.length (textoOn) > 256
then putStrLn $ " Yours Characters are: " ++ (show(T.length (textoOn))) ++" (Number Maximun of characters are 255) "
else do
putStrLn $ " Yours Characters are: " ++ (show(T.length (textoOn))) ++ ". Thanks for used me"
let bock = choseBlock ( T.length (textoOn))
g <- newStdGen
g <- newStdGen
texto <- encryptext g bock password vectorIV (E.encodeUtf8 textoOn)
>>>>>>> Alpha2
-- B.writeFile fileName2 texto
if B.length texto == 256
......@@ -152,9 +181,17 @@ main = do
let block = choseBlock ( num )
text <- decryptext password vectorIV textoMatrix block
putStrLn "Decrypting Text---- is OK"
<<<<<<< HEAD
--The 217 ASCII is the end of the text
let textoInt = B.elemIndex 217 text
putStrLn $ show (word8toString (B.unpack (B.take (fromJust textoInt) text)))
=======
putStrLn $ show (B.take 20 text)
-- The 217 ASCII is the end of the text
let textoInt = B.elemIndex 217 text
--putStrLn $ show (B.take (fromJust textoInt) text)
TIO.putStrLn (E.decodeUtf8(B.take (fromJust textoInt) text))
>>>>>>> Alpha2
else do
-- Two Block
......@@ -171,7 +208,14 @@ main = do
--putStrLn $ show (text)
-- The 217 ASCII is the end of the text
let textoInt = B.elemIndex 217 text
<<<<<<< HEAD
putStrLn $ show (word8toString (B.unpack (B.take (fromJust textoInt) text)))
=======
--putStrLn $ show (B.take (fromJust textoInt) text)
TIO.putStrLn (E.decodeUtf8(B.take (fromJust textoInt) text))
>>>>>>> Alpha2
otherwise ->do
......
......@@ -30,6 +30,7 @@ dependencies:
library:
source-dirs: src
executables:
CrypText-exe:
main: Main.hs
......@@ -51,7 +52,20 @@ executables:
dependencies:
- CrypText
<<<<<<< HEAD
=======
KeyGen-exe:
main: Main.hs
source-dirs: KeyGen
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- CrypText
>>>>>>> Alpha2
......
......@@ -3,23 +3,19 @@ module EncrypText
,decryptext
) where
import RandomGenerator
import LayerAES256
import NukeBull
import System.Random
import Crypto.Cipher.AES (AES256)
import Crypto.Cipher.Types (BlockCipher(..), Cipher(..),IV, makeIV)
import Crypto.Error (throwCryptoError)
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
encryptext :: (RandomGen g) => g -> Int -> B.ByteString -> B.ByteString -> String -> IO B.ByteString
encryptext :: (RandomGen g) => g -> Int -> B.ByteString -> B.ByteString -> B.ByteString -> IO B.ByteString
encryptext g num key vector msg = do
let text = entrophyBS num (BC.pack msg) g
let text = entrophyBS num msg g
let mInitIV = makeIV vector
case mInitIV of
Nothing -> error "Failed to generate and initialization vector."
......
module LayerAES256
(encryptAES256
,decryptAES256
) where
import Crypto.Cipher.AES (AES256)
import Crypto.Cipher.Types (BlockCipher(..), Cipher(..),IV, makeIV)
import Crypto.Error (throwCryptoError)
import qualified Data.ByteString as B
encryptAES256 :: B.ByteString -> IV AES256 -> B.ByteString -> B.ByteString
encryptAES256 key cIV plainData = cbcEncrypt ctx cIV plainData
where ctx :: AES256
ctx = throwCryptoError $ cipherInit key
decryptAES256 :: B.ByteString -> IV AES256 -> B.ByteString -> B.ByteString
decryptAES256 key cIV plainData = cbcDecrypt ctx cIV plainData
where ctx :: AES256
ctx = throwCryptoError $ cipherInit key
module RandomGenerator
(deriveKey
module NukeBull
(stringtoWord8
,word8toString
,randomString
,generator
,randomBytes
......@@ -8,6 +9,9 @@ module RandomGenerator
,extendW8
,entrophyBS
,entrophyW8
,encryptAES256
,decryptAES256
,deriveKey
,decryptEntrophy
,passwordRows
,passwordCols
......@@ -19,33 +23,36 @@ import System.Random
import Data.List
import Data.Word
import Data.Bits
import Data.Char
import qualified Data.ByteString as B
import Crypto.Cipher.AES (AES256)
import Crypto.Cipher.Types (BlockCipher(..), Cipher(..),IV, makeIV)
import Crypto.Error (throwCryptoError)
import Crypto.Random(getSystemDRG, randomBytesGenerate)
import Crypto.KDF.Scrypt (generate, Parameters(..))
saltSize = 64
paramN = 64:: Word64
paramR = 8
paramP = 1
paramKeyLen = 256
--Scrypt KDF
deriveKey :: B.ByteString -> B.ByteString -> B.ByteString
deriveKey password salt = generate params password salt
where params = Parameters {n = paramN, r = paramR, p = paramP, outputLength = paramKeyLen}
-- for generating the salt
randomString :: Int -> IO B.ByteString
randomString size = do
drg <- getSystemDRG
let (bytes, _) = randomBytesGenerate size drg
return bytes
stringtoWord8 :: [Char] -> [Word8]
stringtoWord8 [] = []
stringtoWord8 (x:xs) = [fromIntegral $ ord x] ++ stringtoWord8 xs
--ASCII 128 bites for ñ áéíóú (adding if need more)
chr2 :: Int -> Char
chr2 x
| x==241 = '~'
| x==225 = 'a'
| x==233 = 'e'
| x==237 = 'i'
| x==243 = 'o'
| x==250 = 'u'
| otherwise = chr x
word8toString :: [Word8] -> [Char]
word8toString [] = []
word8toString (x:xs) = [chr2 $ fromIntegral x] ++ word8toString xs
-- Randon generator, Int List Numbers
-- Need Random g for init (g <- getStdGen, g <- newStdGen)
generator :: (RandomGen g ) => Int -> g -> [Int]
generator n g = take n $ randomRs (0,255) g
......@@ -66,9 +73,12 @@ randomBytesString n g = B.pack $ randomBytes n g
-- Need Int > B.lenght [Word8]
-- msgExtend n bytes :: Word8 + Random Word8
---- Expand text
extendW8 :: (RandomGen g ) => Int -> [Word8] -> g -> [Word8]
extendW8 n a g
| n > B.length (B.pack a) = a ++ (B.unpack (B.take (n - B.length (B.pack a)) (randomBytesString n g)))
| n > B.length (B.pack a) = a ++ [217] ++ (B.unpack (B.take (n -1 - B.length (B.pack a)) (randomBytesString n g)))
| n <= B.length (B.pack a) = a
-- Need Random g for init (g <- getStdGen, g <- newStdGen)
......@@ -80,7 +90,7 @@ extendBS n a g = B.pack (extendW8 n (B.unpack a) g)
-- Need Random g for init (g <- getStdGen, g <- newStdGen)
-- Need Int > B.lenght [Word8] else return [Word8]
-- [Word8] xor Random n ++ Random n
-- Random n ++ [Word8] xor Random n
entrophyW8 :: (RandomGen g) => Int -> [Word8] -> g -> [Word8]
entrophyW8 n a g = if n > B.length (B.pack a) then
......@@ -91,7 +101,7 @@ entrophyW8 n a g = if n > B.length (B.pack a) then
else a
entrophyBS :: (RandomGen g) => Int -> B.ByteString -> g -> B.ByteString
entrophyBS n a g = B.pack $ entrophyW8 n (B.unpack a ) g
entrophyBS n a g = B.pack $ entrophyW8 n (B.unpack a ) g
decryptEntrophy :: Int -> B.ByteString -> B.ByteString
......@@ -100,9 +110,41 @@ decryptEntrophy n a =
a2 = B.unpack $ B.drop n a
in B.pack (zipWith xor a1 a2)
-- AES ciPher Lv2
encryptAES256 :: B.ByteString -> IV AES256 -> B.ByteString -> B.ByteString
encryptAES256 key cIV plainData = cbcEncrypt ctx cIV plainData
where ctx :: AES256
ctx = throwCryptoError $ cipherInit key
decryptAES256 :: B.ByteString -> IV AES256 -> B.ByteString -> B.ByteString
decryptAES256 key cIV plainData = cbcDecrypt ctx cIV plainData
where ctx :: AES256
ctx = throwCryptoError $ cipherInit key
-- NukeBull Cipher Level 3
saltSize = 64
paramN = 32:: Word64
paramR = 8
paramP = 1
paramKeyLen = 256
--Scrypt KDF
deriveKey :: B.ByteString -> B.ByteString -> B.ByteString
deriveKey password salt = generate params password salt
where params = Parameters {n = paramN, r = paramR, p = paramP, outputLength = paramKeyLen}
-- for generating the salt
randomString :: Int -> IO B.ByteString
randomString size = do
drg <- getSystemDRG
let (bytes, _) = randomBytesGenerate size drg
return bytes
-- NukeBull Cipher
passwordRows :: [Word8] -> [Int]
passwordRows x = map (`div` 16) (map fromIntegral x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment