Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1690 connectés 

  FORUM HardWare.fr
  Programmation
  Divers

  [Haskell] cryptage ecb

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Haskell] cryptage ecb

n°2212849
titely
Posté le 06-12-2013 à 21:42:48  profilanswer
 

Bonjour à tous,
 
J'ai un TP à faire en Haskell concernant le crypatge ECB et CBC, mais j'ai un problème pour permuter les bits, je n'ai absolument aucune idée de comment faire.
 
Voici ce que j'ai déjà fait (les signatures des fonctions sont fournies pas le professeur)  
 
{-# LANGUAGE OverloadedStrings #-}
 
module CryptoSys where
 
import qualified Data.Char as C
 
--Ecris un entier en binaire sur 7 bits
toBin :: Int -> [Int]
toBin x = ajoute_zero(toBinTmp x)
 
--Ecris un entier en binaire
toBinTmp :: Int -> [Int]
toBinTmp 0 = [0]
toBinTmp 1 = [1]
toBinTmp x
 | x `mod` 2 == 0 = toBinTmp (x `div` 2) ++ [0]
 | otherwise = toBinTmp (x `div` 2) ++ [1]
 
 
--ajoute des zero pour avoir des liste de 7 éléments
ajoute_zero :: [Int] -> [Int]
ajoute_zero liste
 | length liste < 7 = ajoute_zero ([0] ++ liste)
 | otherwise = liste
 
 
--transforme un nombre binaire en nombre décimal
toDec :: [Int] -> Int
toDec x = if length x == 1
 then (head x)
 else (head x)*2^((length x)-1) + toDec (tail x)
 
 
--transforme une chaine de caractères en binaire
stringToBin :: String -> [[Int]]
stringToBin [] = []
stringToBin (tete:queue) = toBin(ord tete):(stringToBin queue)
 
 
 
per :: Int -> Int
per 1 = 3
per 2 = 1
per 3 = 4
per 4 = 2
per 5 = 6
per 6 = 5
per 7 = 7
per x = error "not definied"
 
 
iper :: Int -> Int
iper 1 = 2
iper 2 = 4
iper 3 = 1
iper 4 = 3
iper 5 = 6
iper 6 = 5
iper 7 = 7
iper x = error "not definied"
 
 
--permBits :: (Int -> Int) -> [a] -> [a]
 
 
--ecb :: (Int -> Int) -> String -> String
 
 
xor :: Int -> Int -> Int
xor 0 0 = 0
xor 1 0 = 1
xor 0 1 = 1
xor 1 1 = 0
 
--cbc_crypt :: (Int -> Int) -> [Int] -> String -> String
 
 
--cbc_decrypt :: (Int -> Int) -> [Int] -> String -> String
 
 
 
chr 0  = 'à'
chr 1  = 'â'
chr 2  = 'é'
chr 3  = 'è'
chr 4  = 'ê'
chr 5  = 'ë'
chr 6  = 'î'
chr 7  = 'ï'
chr 8  = 'ô'
chr 9  = 'ö'
chr 10 = 'ù'
chr 11 = 'û'
chr 12 = 'ü'
chr 13 = 'ç'
chr 14 = 'æ'
chr 15 = 'œ'
chr 16 = 'À'
chr 17 = 'Â'
chr 18 = 'É'
chr 19 = 'È'
chr 20 = 'Ê'
chr 21 = 'Ë'
chr 22 = 'Î'
chr 23 = 'Ï'
chr 24 = 'Ô'
chr 25 = 'Ö'
chr 26 = 'Ù'
chr 27 = 'Û'
chr 28 = 'Ü'
chr 29 = 'Ç'
chr 30 = 'Æ'
chr 31 = 'Œ'
chr 127 = '€'
chr x = C.chr x
 
 
 
ord  'à' = 0
ord  'â' = 1
ord  'é' = 2
ord  'è' = 3
ord  'ê' = 4
ord  'ë' = 5
ord  'î' = 6
ord  'ï' = 7
ord  'ô' = 8  
ord  'ö' = 9  
ord  'ù' = 10
ord  'û' = 11
ord  'ü' = 12  
ord  'ç' = 13
ord  'æ' = 14
ord  'œ' = 15
ord  'À' = 16
ord  'Â' = 17
ord  'É' = 18
ord  'È' = 19
ord  'Ê' = 20
ord  'Ë' = 21
ord  'Î' = 22
ord  'Ï' = 23
ord  'Ô' = 24
ord  'Ö' = 25
ord  'Ù' = 26
ord  'Û' = 27
ord  'Ü' = 28
ord  'Ç' = 29
ord  'Æ' = 30
ord  'Œ' = 31
ord  '€' = 127
ord x = C.ord x
 
Mon problème concerne la fonction permBits
 
Si quelqu'un pouvait m'aider, ce serait vraiment génial !
Cordialement

mood
Publicité
Posté le 06-12-2013 à 21:42:48  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Divers

  [Haskell] cryptage ecb

 

Sujets relatifs
Cryptage et decryptage C++[Recherche] Algorithme de cryptage asymétrique
cryptage d'un message à plusieurs destinatairesCryptage SSL
CryptageCryptage asymetrique d'URL?
Signature et Cryptage fichier XML avec phpQuel est le type de cryptage de ce mot de passe?:
[Apache] Cryptage (Pseudo)-MD5 via htpasswdCryptage RSA
Plus de sujets relatifs à : [Haskell] cryptage ecb


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR