Prototype d'encodage de texte

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Prototype d'encodage de texte

Message par Guimauve »

Bnojur à tous,

Le texte n'est pas crypté mais codé. Le principe de fonctionnement pour le codage du texte est le suivant :

On divise la chaine à codé en bloc de 3 codes ascii pour former une série de Vecteur.
On fait le produit d'une matrice 3X3 inversible avec chacun des vecteurs.

Pour décoder le texte le fonctionnement est le suivant :

Avec la matrice inverse utilisée pour coder le texte on fait le produit MatriceInverse avec la série de vecteurs.
On restore le texte caractère par caratère pour la série de vecteurs.

A+
Guimauve

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Prototype d'encodage de texte
; Fichier : Source principal
; Version : 1.0.0
; Programmation : OK
; Programmé par : Guimauve
; Date : 28-10-2007
; Mise à jour : 28-10-2007
; Codé avec PureBasic V4.10
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; CODE GÉNÉRÉ AUTOMATIQUEMENT, NE PAS MODIFIER À
; MOINS D'AVOIR UNE RAISON TRÈS TRÈS VALABLE !!!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration de la Structure <<<<<

Structure Hook
  
  Counter.l
  CurrentPtr.l
  RootPtr.l
  TailPtr.l
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<

Macro SetHookCounter(HookA, P_Counter)
  
  HookA\Counter = P_Counter
  
EndMacro

Macro SetHookCurrentPtr(HookA, P_CurrentPtr)
  
  HookA\CurrentPtr = P_CurrentPtr
  
EndMacro

Macro SetHookRootPtr(HookA, P_RootPtr)
  
  HookA\RootPtr = P_RootPtr
  
EndMacro

Macro SetHookTailPtr(HookA, P_TailPtr)
  
  HookA\TailPtr = P_TailPtr
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<

Macro GetHookCounter(HookA)
  
  HookA\Counter
  
EndMacro

Macro GetHookCurrentPtr(HookA)
  
  HookA\CurrentPtr
  
EndMacro

Macro GetHookRootPtr(HookA)
  
  HookA\RootPtr
  
EndMacro

Macro GetHookTailPtr(HookA)
  
  HookA\TailPtr
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Reset complet <<<<<

Macro ResetHook(HookA)
  
  SetHookCounter(HookA, 0)
  SetHookCurrentPtr(HookA, 0)
  SetHookRootPtr(HookA, 0)
  SetHookTailPtr(HookA, 0)
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code généré en : 00.015 secondes <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; CODE GÉNÉRÉ AUTOMATIQUEMENT, NE PAS MODIFIER À
; MOINS D'AVOIR UNE RAISON TRÈS TRÈS VALABLE !!!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Notes : Matrix33L
;
; La matrice se présente sous la forme suivante :
;
; Éléments Matrice --> Index du tableau 1D
;   3x3 éléments   -->   9 case de 0 à 8
;  
;  [e11, e12, e13] -->    [0, 1, 2] 
;  [e21, e22, e23] -->    [3, 4, 5]
;  [e31, e32, e33] -->    [6, 7, 8]
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration de la Structure <<<<<

Structure Matrix33L
  
  e11.l
  e12.l
  e13.l
  e21.l
  e22.l
  e23.l
  e31.l
  e32.l
  e33.l
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<

Macro SetMatrix33Le11(MatrixA, P_e11)
  
  MatrixA\e11 = P_e11
  
EndMacro

Macro SetMatrix33Le12(MatrixA, P_e12)
  
  MatrixA\e12 = P_e12
  
EndMacro

Macro SetMatrix33Le13(MatrixA, P_e13)
  
  MatrixA\e13 = P_e13
  
EndMacro

Macro SetMatrix33Le21(MatrixA, P_e21)
  
  MatrixA\e21 = P_e21
  
EndMacro

Macro SetMatrix33Le22(MatrixA, P_e22)
  
  MatrixA\e22 = P_e22
  
EndMacro

Macro SetMatrix33Le23(MatrixA, P_e23)
  
  MatrixA\e23 = P_e23
  
EndMacro

Macro SetMatrix33Le31(MatrixA, P_e31)
  
  MatrixA\e31 = P_e31
  
EndMacro

Macro SetMatrix33Le32(MatrixA, P_e32)
  
  MatrixA\e32 = P_e32
  
EndMacro

Macro SetMatrix33Le33(MatrixA, P_e33)
  
  MatrixA\e33 = P_e33
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<

Macro GetMatrix33Le11(MatrixA)
  
  MatrixA\e11
  
EndMacro

Macro GetMatrix33Le12(MatrixA)
  
  MatrixA\e12
  
EndMacro

Macro GetMatrix33Le13(MatrixA)
  
  MatrixA\e13
  
EndMacro

Macro GetMatrix33Le21(MatrixA)
  
  MatrixA\e21
  
EndMacro

Macro GetMatrix33Le22(MatrixA)
  
  MatrixA\e22
  
EndMacro

Macro GetMatrix33Le23(MatrixA)
  
  MatrixA\e23
  
EndMacro

Macro GetMatrix33Le31(MatrixA)
  
  MatrixA\e31
  
EndMacro

Macro GetMatrix33Le32(MatrixA)
  
  MatrixA\e32
  
EndMacro

Macro GetMatrix33Le33(MatrixA)
  
  MatrixA\e33
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur DivideByScalar : R = A / Scalar <<<<<

Macro DivideByScalarMatrix33L(MatrixR, MatrixA, Scalar)
  
  SetMatrix33Le11(MatrixR, GetMatrix33Le11(MatrixA) / Scalar)
  SetMatrix33Le12(MatrixR, GetMatrix33Le12(MatrixA) / Scalar)
  SetMatrix33Le13(MatrixR, GetMatrix33Le13(MatrixA) / Scalar)
  SetMatrix33Le21(MatrixR, GetMatrix33Le21(MatrixA) / Scalar)
  SetMatrix33Le22(MatrixR, GetMatrix33Le22(MatrixA) / Scalar)
  SetMatrix33Le23(MatrixR, GetMatrix33Le23(MatrixA) / Scalar)
  SetMatrix33Le31(MatrixR, GetMatrix33Le31(MatrixA) / Scalar)
  SetMatrix33Le32(MatrixR, GetMatrix33Le32(MatrixA) / Scalar)
  SetMatrix33Le33(MatrixR, GetMatrix33Le33(MatrixA) / Scalar)
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Reset complet <<<<<

Macro ResetMatrix33L(MatrixA)
  
  SetMatrix33Le11(MatrixA, 0)
  SetMatrix33Le12(MatrixA, 0)
  SetMatrix33Le13(MatrixA, 0)
  SetMatrix33Le21(MatrixA, 0)
  SetMatrix33Le22(MatrixA, 0)
  SetMatrix33Le23(MatrixA, 0)
  SetMatrix33Le31(MatrixA, 0)
  SetMatrix33Le32(MatrixA, 0)
  SetMatrix33Le33(MatrixA, 0)
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Copy : A = Source : B = Destination <<<<<

Macro CopyMatrix33L(MatrixA, MatrixB)
  
  SetMatrix33Le11(MatrixB, GetMatrix33Le11(MatrixA))
  SetMatrix33Le12(MatrixB, GetMatrix33Le12(MatrixA))
  SetMatrix33Le13(MatrixB, GetMatrix33Le13(MatrixA))
  SetMatrix33Le21(MatrixB, GetMatrix33Le21(MatrixA))
  SetMatrix33Le22(MatrixB, GetMatrix33Le22(MatrixA))
  SetMatrix33Le23(MatrixB, GetMatrix33Le23(MatrixA))
  SetMatrix33Le31(MatrixB, GetMatrix33Le31(MatrixA))
  SetMatrix33Le32(MatrixB, GetMatrix33Le32(MatrixA))
  SetMatrix33Le33(MatrixB, GetMatrix33Le33(MatrixA))
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code généré en : 00.031 secondes <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs ligne par ligne <<<<<

Macro SetMatrix33LLine1(MatrixA, P_e11, P_e12, P_e13)
  
  SetMatrix33Le11(MatrixA, P_e11)
  SetMatrix33Le12(MatrixA, P_e12)
  SetMatrix33Le13(MatrixA, P_e13)
  
EndMacro

Macro SetMatrix33LLine2(MatrixA, P_e21, P_e22, P_e23)
  
  SetMatrix33Le21(MatrixA, P_e21)
  SetMatrix33Le22(MatrixA, P_e22)
  SetMatrix33Le23(MatrixA, P_e23)
  
EndMacro

Macro SetMatrix33LLine3(MatrixA, P_e31, P_e32, P_e33)
  
  SetMatrix33Le31(MatrixA, P_e31)
  SetMatrix33Le32(MatrixA, P_e32)
  SetMatrix33Le33(MatrixA, P_e33)
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur CofactorInverse <<<<<

Procedure CofactorInverseMatrix33L(*MatrixA.Matrix33L, *Inverse.Matrix33L)
  
  CopyMatrix33L(*MatrixA, CopyA.Matrix33L)
  
  SetMatrix33Le11(*Inverse, GetMatrix33Le22(CopyA) * GetMatrix33Le33(CopyA) - GetMatrix33Le23(CopyA) * GetMatrix33Le32(CopyA))
  SetMatrix33Le12(*Inverse, GetMatrix33Le13(CopyA) * GetMatrix33Le32(CopyA) - GetMatrix33Le12(CopyA) * GetMatrix33Le33(CopyA))
  SetMatrix33Le13(*Inverse, GetMatrix33Le12(CopyA) * GetMatrix33Le23(CopyA) - GetMatrix33Le13(CopyA) * GetMatrix33Le22(CopyA))
  SetMatrix33Le21(*Inverse, GetMatrix33Le23(CopyA) * GetMatrix33Le31(CopyA) - GetMatrix33Le21(CopyA) * GetMatrix33Le33(CopyA))
  SetMatrix33Le22(*Inverse, GetMatrix33Le11(CopyA) * GetMatrix33Le33(CopyA) - GetMatrix33Le13(CopyA) * GetMatrix33Le31(CopyA))
  SetMatrix33Le23(*Inverse, GetMatrix33Le13(CopyA) * GetMatrix33Le21(CopyA) - GetMatrix33Le11(CopyA) * GetMatrix33Le23(CopyA))
  SetMatrix33Le31(*Inverse, GetMatrix33Le21(CopyA) * GetMatrix33Le32(CopyA) - GetMatrix33Le22(CopyA) * GetMatrix33Le31(CopyA))
  SetMatrix33Le32(*Inverse, GetMatrix33Le12(CopyA) * GetMatrix33Le31(CopyA) - GetMatrix33Le11(CopyA) * GetMatrix33Le32(CopyA))
  SetMatrix33Le33(*Inverse, GetMatrix33Le11(CopyA) * GetMatrix33Le22(CopyA) - GetMatrix33Le12(CopyA) * GetMatrix33Le21(CopyA)) 
  
  Cofactor_Determinant.l = GetMatrix33Le11(CopyA) * GetMatrix33Le11(*Inverse) + GetMatrix33Le12(CopyA) * GetMatrix33Le21(*Inverse) + GetMatrix33Le13(CopyA) * GetMatrix33Le31(*Inverse)  
  
  If Cofactor_Determinant <> 0.0
    DivideByScalarMatrix33L(*Inverse, *Inverse, Cofactor_Determinant)
  EndIf 
  
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; CODE GÉNÉRÉ AUTOMATIQUEMENT, NE PAS MODIFIER À
; MOINS D'AVOIR UNE RAISON TRÈS TRÈS VALABLE !!!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration de la Structure <<<<<

Structure Vector3L
  
  i.l
  j.l
  k.l
  NextPtr.l
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<

Macro SetVector3Li(VectorA, P_i)
  
  VectorA\i = P_i
  
EndMacro

Macro SetVector3Lj(VectorA, P_j)
  
  VectorA\j = P_j
  
EndMacro

Macro SetVector3Lk(VectorA, P_k)
  
  VectorA\k = P_k
  
EndMacro

Macro SetVector3LNextPtr(VectorA, P_NextPtr)
  
  VectorA\NextPtr = P_NextPtr
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<

Macro GetVector3Li(VectorA)
  
  VectorA\i
  
EndMacro

Macro GetVector3Lj(VectorA)
  
  VectorA\j
  
EndMacro

Macro GetVector3Lk(VectorA)
  
  VectorA\k
  
EndMacro

Macro GetVector3LNextPtr(VectorA)
  
  VectorA\NextPtr
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Reset complet <<<<<

Macro ResetVector3L(VectorA)
  
  SetVector3Li(VectorA, 0)
  SetVector3Lj(VectorA, 0)
  SetVector3Lk(VectorA, 0)
  SetVector3LNextPtr(VectorA, 0)
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Le Constructeur <<<<<

Procedure.l CreateNewVector3L()
  
  *NewVector3L.Vector3L = AllocateMemory(SizeOf(Vector3L))
  
  If *NewVector3L = #Null
    MessageRequester("Fatal Error", "CreateNewVector3L() - Impossible to Allocate Memory !")
    End
  EndIf
  
  ProcedureReturn *NewVector3L
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Ajout d'un Maillon à la chaine <<<<<

Procedure.l AddLinkToChainOfVector3L(*Hook.Hook)
  
  *NewVector3L.Vector3L = CreateNewVector3L()
  
  If GetHookRootPtr(*Hook) = #Null
    SetHookRootPtr(*Hook, *NewVector3L)
  Else
    *Tail.Vector3L = GetHookTailPtr(*Hook)
    SetVector3LNextPtr(*Tail, *NewVector3L)
  EndIf
  
  SetHookTailPtr(*Hook, *NewVector3L)
  SetHookCurrentPtr(*Hook, *NewVector3L)
  SetHookCounter(*Hook, GetHookCounter(*Hook) + 1)
  
  ProcedureReturn *NewVector3L
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Private - Destruction récursive de la chaine <<<<<

Procedure PrivateDestroyChainOfVector3L(*VectorA.Vector3L)
  
  *NextVector3L.Vector3L = GetVector3LNextPtr(*VectorA)
  ResetVector3L(*VectorA)
  FreeMemory(*VectorA)
  
  If *NextVector3L <> #Null
    PrivateDestroyChainOfVector3L(*NextVector3L)
  EndIf
  
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Destruction de la chaine <<<<<

Procedure DestroyChainOfVector3L(*Hook.Hook)
  
  *RootVector3L.Vector3L = GetHookRootPtr(*Hook)
  
  If *RootVector3L <> #Null
    PrivateDestroyChainOfVector3L(*RootVector3L)
    ResetHook(*Hook)
  EndIf
  
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Lecture fichier Binaire <<<<<

Procedure ReadChainOfVector3L(FileID.l, *Hook.Hook)
  
  LinkMax.l = ReadLong(FileID)
  
  For LinkIndex = 0 To LinkMax - 1
    
    *VectorA.Vector3L = AddLinkToChainOfVector3L(*Hook)
    
    SetVector3Li(*VectorA, ReadLong(FileID))
    SetVector3Lj(*VectorA, ReadLong(FileID))
    SetVector3Lk(*VectorA, ReadLong(FileID))
    
  Next
  
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Écriture fichier Binaire <<<<<

Procedure WriteChainOfVector3L(FileID.l, *Hook.Hook)
  
  WriteLong(FileID, GetHookCounter(*Hook))
  
  *VectorA.Vector3L = GetHookRootPtr(*Hook)
  
  While *VectorA <> #Null
    
    WriteLong(FileID, GetVector3Li(*VectorA))
    WriteLong(FileID, GetVector3Lj(*VectorA))
    WriteLong(FileID, GetVector3Lk(*VectorA))
    
    *VectorA = GetVector3LNextPtr(*VectorA)
    
  Wend
  
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code généré en : 00.047 secondes <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; CODE GÉNÉRÉ AUTOMATIQUEMENT, NE PAS MODIFIER À
; MOINS D'AVOIR UNE RAISON TRÈS TRÈS VALABLE !!!
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration de la Structure <<<<<

Structure EncodeText
  
  CodeMatrixID.b
  ChainOfVector.Hook ; Vector3L
  CodeMatrix.Matrix33L[4]
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<

Macro SetEncodeTextCodeMatrixID(EncodeTextA, P_CodeMatrixID)
  
  EncodeTextA\CodeMatrixID = P_CodeMatrixID
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<

Macro GetEncodeTextCodeMatrixID(EncodeTextA)
  
  EncodeTextA\CodeMatrixID
  
EndMacro

Macro GetEncodeTextChainOfVector(EncodeTextA)
  
  EncodeTextA\ChainOfVector
  
EndMacro

Macro GetEncodeTextCodeMatrix(EncodeTextA, Index)
  
  EncodeTextA\CodeMatrix[Index]
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Reset complet <<<<<

Macro ResetEncodeText(EncodeTextA)
  
  SetEncodeTextCodeMatrixID(EncodeTextA, 0)
  DestroyChainOfVector3L(GetEncodeTextChainOfVector(EncodeTextA))
  
  For Index = 0 To 3
    ResetMatrix33L(GetEncodeTextCodeMatrix(EncodeTextA, Index))
  Next
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Lecture fichier Binaire <<<<<

Procedure ReadEncodeText(FileID.l, *EncodeTextA.EncodeText)
  
  SetEncodeTextCodeMatrixID(*EncodeTextA, ReadByte(FileID))
  ReadChainOfVector3L(FileID, GetEncodeTextChainOfVector(*EncodeTextA))

EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Écriture fichier Binaire <<<<<

Procedure WriteEncodeText(FileID.l, *EncodeTextA.EncodeText)
  
  WriteByte(FileID, GetEncodeTextCodeMatrixID(*EncodeTextA))
  WriteChainOfVector3L(FileID, GetEncodeTextChainOfVector(*EncodeTextA))
  
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code généré en : 00.016 secondes <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Procedure InitializeEncodeText(*EncodeTextA.EncodeText)
  
  ; Sélection aléatoire d'une matrice d'encodage
  SetEncodeTextCodeMatrixID(*EncodeTextA, Random(3))
  
  ; Matrice d'encodage ID = 0
  SetMatrix33LLine1(GetEncodeTextCodeMatrix(*EncodeTextA, 0),  1, 2, 2)
  SetMatrix33LLine2(GetEncodeTextCodeMatrix(*EncodeTextA, 0),  3, 1, 0)
  SetMatrix33LLine3(GetEncodeTextCodeMatrix(*EncodeTextA, 0),  1, 1, 1)
  
  ; Matrice d'encodage ID = 2
  SetMatrix33LLine1(GetEncodeTextCodeMatrix(*EncodeTextA, 2),  2, 1, 0)
  SetMatrix33LLine2(GetEncodeTextCodeMatrix(*EncodeTextA, 2), -1, 1, 2)
  SetMatrix33LLine3(GetEncodeTextCodeMatrix(*EncodeTextA, 2),  3, 2, 1)
  
  ; Matrice Inverse de la matrice ID = 0
  CofactorInverseMatrix33L(GetEncodeTextCodeMatrix(*EncodeTextA, 0), GetEncodeTextCodeMatrix(*EncodeTextA, 1))
  
  ; Matrice Inverse de la matrice ID = 2
  CofactorInverseMatrix33L(GetEncodeTextCodeMatrix(*EncodeTextA, 2), GetEncodeTextCodeMatrix(*EncodeTextA, 3))
  
EndProcedure

Procedure TransformTextToEncodeText(*EncodeTextA.EncodeText, Texte.s)
  
  Nb_Car.l = Len(Texte)
  
  For Index = 0 To Nb_Car Step 3
    
    *VectorA.Vector3L = AddLinkToChainOfVector3L(GetEncodeTextChainOfVector(*EncodeTextA))
    
    SetVector3Li(*VectorA, Asc(Mid(Texte, Index + 1, 1)))
    SetVector3Lj(*VectorA, Asc(Mid(Texte, Index + 2, 1)))
    SetVector3Lk(*VectorA, Asc(Mid(Texte, Index + 3, 1)))
    
    Temp_I = GetMatrix33Le11(GetEncodeTextCodeMatrix(*EncodeTextA, GetEncodeTextCodeMatrixID(*EncodeTextA))) * GetVector3Li(*VectorA) + GetMatrix33Le12(GetEncodeTextCodeMatrix(*EncodeTextA, GetEncodeTextCodeMatrixID(*EncodeTextA))) * GetVector3Lj(*VectorA) + GetMatrix33Le13(GetEncodeTextCodeMatrix(*EncodeTextA, GetEncodeTextCodeMatrixID(*EncodeTextA))) * GetVector3Lk(*VectorA)
    Temp_J = GetMatrix33Le21(GetEncodeTextCodeMatrix(*EncodeTextA, GetEncodeTextCodeMatrixID(*EncodeTextA))) * GetVector3Li(*VectorA) + GetMatrix33Le22(GetEncodeTextCodeMatrix(*EncodeTextA, GetEncodeTextCodeMatrixID(*EncodeTextA))) * GetVector3Lj(*VectorA) + GetMatrix33Le23(GetEncodeTextCodeMatrix(*EncodeTextA, GetEncodeTextCodeMatrixID(*EncodeTextA))) * GetVector3Lk(*VectorA)
    Temp_K = GetMatrix33Le31(GetEncodeTextCodeMatrix(*EncodeTextA, GetEncodeTextCodeMatrixID(*EncodeTextA))) * GetVector3Li(*VectorA) + GetMatrix33Le32(GetEncodeTextCodeMatrix(*EncodeTextA, GetEncodeTextCodeMatrixID(*EncodeTextA))) * GetVector3Lj(*VectorA) + GetMatrix33Le33(GetEncodeTextCodeMatrix(*EncodeTextA, GetEncodeTextCodeMatrixID(*EncodeTextA))) * GetVector3Lk(*VectorA)
    
    SetVector3Li(*VectorA, Temp_I)
    SetVector3Lj(*VectorA, Temp_J)
    SetVector3Lk(*VectorA, Temp_K)
    
  Next
  
EndProcedure

Procedure.s RestoreTextFromEncodeText(*EncodeTextA.EncodeText) 
  
  ; En fonction de la matrice utilisé à l'encodage, il faut sélectionner
  ; la matrice inverse correspondante. 
  
  ; La matrice 0 est l'inverse de la 1
  ; La matrice 1 est l'inverse de la 0
  ; La matrice 2 est l'inverse de la 3
  ; La matrice 3 est l'inverse de la 2
  
  If GetEncodeTextCodeMatrixID(*EncodeTextA) = 0
    CodeMatrixID = 1
  ElseIf GetEncodeTextCodeMatrixID(*EncodeTextA) = 1
    CodeMatrixID = 0
  ElseIf GetEncodeTextCodeMatrixID(*EncodeTextA) = 2
    CodeMatrixID = 3
  ElseIf GetEncodeTextCodeMatrixID(*EncodeTextA) = 3
    CodeMatrixID = 2
  EndIf
  
  *VectorA.Vector3L = GetHookRootPtr(GetEncodeTextChainOfVector(*EncodeTextA))
  
  While *VectorA <> #Null
    
    Temp_I = GetMatrix33Le11(GetEncodeTextCodeMatrix(*EncodeTextA, CodeMatrixID)) * GetVector3Li(*VectorA) + GetMatrix33Le12(GetEncodeTextCodeMatrix(*EncodeTextA, CodeMatrixID)) * GetVector3Lj(*VectorA) + GetMatrix33Le13(GetEncodeTextCodeMatrix(*EncodeTextA, CodeMatrixID)) * GetVector3Lk(*VectorA)
    Temp_J = GetMatrix33Le21(GetEncodeTextCodeMatrix(*EncodeTextA, CodeMatrixID)) * GetVector3Li(*VectorA) + GetMatrix33Le22(GetEncodeTextCodeMatrix(*EncodeTextA, CodeMatrixID)) * GetVector3Lj(*VectorA) + GetMatrix33Le23(GetEncodeTextCodeMatrix(*EncodeTextA, CodeMatrixID)) * GetVector3Lk(*VectorA)
    Temp_K = GetMatrix33Le31(GetEncodeTextCodeMatrix(*EncodeTextA, CodeMatrixID)) * GetVector3Li(*VectorA) + GetMatrix33Le32(GetEncodeTextCodeMatrix(*EncodeTextA, CodeMatrixID)) * GetVector3Lj(*VectorA) + GetMatrix33Le33(GetEncodeTextCodeMatrix(*EncodeTextA, CodeMatrixID)) * GetVector3Lk(*VectorA)
    
    Text.s = Text + Chr(Temp_I) + Chr(Temp_J) + Chr(Temp_K)
    
    *VectorA = GetVector3LNextPtr(*VectorA)
    
  Wend
  
  ProcedureReturn Text
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< CODE DE DÉMONSTRATION <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

InitializeEncodeText(EncodeText.EncodeText)
InitializeEncodeText(EncodeText2.EncodeText)

TransformTextToEncodeText(EncodeText, "Les carottes sont cuites à point !")

If CreateFile(0, "EncodedText.dat")
  WriteEncodeText(0, EncodeText)
EndIf

If ReadFile(0, "EncodedText.dat")
  ReadEncodeText(0, EncodeText2)
EndIf

Debug RestoreTextFromEncodeText(EncodeText2) 

ResetEncodeText(EncodeText)
ResetEncodeText(EncodeText2)

; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Message par Guimauve »

Bonjour à tous,

Pendant les vacances, je me suis amusé à simplifier mon système d'encodage. De plus, j'ai ajoutée quelques matrices d'encodages afin de le rendre plus difficile à déchiffrer. Voici donc le code de la nouvelle version.

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Read\Write EncodedString
; Nom du fichier : Lib_EncodedString.pb
; Version du fichier : 2.0.0
; Programmation : OK
; Programmé par : Guimauve
; Date : 07-08-2008
; Mise à jour : 15-08-2008
; Codé pour PureBasic V4.20
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration de la Structure <<<<<

Structure Vector3L
  
  i.l
  j.l
  k.l
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<

Macro SetVector3Li(VectorA, P_i)
  
  VectorA\i = P_i
  
EndMacro

Macro SetVector3Lj(VectorA, P_j)
  
  VectorA\j = P_j
  
EndMacro

Macro SetVector3Lk(VectorA, P_k)
  
  VectorA\k = P_k
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<

Macro GetVector3Li(VectorA)
  
  VectorA\i
  
EndMacro

Macro GetVector3Lj(VectorA)
  
  VectorA\j
  
EndMacro

Macro GetVector3Lk(VectorA)
  
  VectorA\k
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Copy : A = Source : B = Destination <<<<<

Macro CopyVector3L(VectorA, VectorB)
  
  SetVector3Li(VectorB, GetVector3Li(VectorA))
  SetVector3Lj(VectorB, GetVector3Lj(VectorA))
  SetVector3Lk(VectorB, GetVector3Lk(VectorA))
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Lecture fichier Binaire <<<<<

Macro ReadVector3L(FileID, VectorA)
  
  ReadData(FileID, VectorA, SizeOf(Vector3L))
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Écriture fichier Binaire <<<<<

Macro WriteVector3L(FileID, VectorA)
  
  WriteData(FileID, VectorA, SizeOf(Vector3L))
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration de la Structure <<<<<

Structure Matrix33L
  
  e11.l
  e12.l
  e13.l
  e21.l
  e22.l
  e23.l
  e31.l
  e32.l
  e33.l
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<

Macro SetMatrix33Le11(MatrixA, P_e11)
  
  MatrixA\e11 = P_e11
  
EndMacro

Macro SetMatrix33Le12(MatrixA, P_e12)
  
  MatrixA\e12 = P_e12
  
EndMacro

Macro SetMatrix33Le13(MatrixA, P_e13)
  
  MatrixA\e13 = P_e13
  
EndMacro

Macro SetMatrix33Le21(MatrixA, P_e21)
  
  MatrixA\e21 = P_e21
  
EndMacro

Macro SetMatrix33Le22(MatrixA, P_e22)
  
  MatrixA\e22 = P_e22
  
EndMacro

Macro SetMatrix33Le23(MatrixA, P_e23)
  
  MatrixA\e23 = P_e23
  
EndMacro

Macro SetMatrix33Le31(MatrixA, P_e31)
  
  MatrixA\e31 = P_e31
  
EndMacro

Macro SetMatrix33Le32(MatrixA, P_e32)
  
  MatrixA\e32 = P_e32
  
EndMacro

Macro SetMatrix33Le33(MatrixA, P_e33)
  
  MatrixA\e33 = P_e33
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<

Macro GetMatrix33Le11(MatrixA)
  
  MatrixA\e11
  
EndMacro

Macro GetMatrix33Le12(MatrixA)
  
  MatrixA\e12
  
EndMacro

Macro GetMatrix33Le13(MatrixA)
  
  MatrixA\e13
  
EndMacro

Macro GetMatrix33Le21(MatrixA)
  
  MatrixA\e21
  
EndMacro

Macro GetMatrix33Le22(MatrixA)
  
  MatrixA\e22
  
EndMacro

Macro GetMatrix33Le23(MatrixA)
  
  MatrixA\e23
  
EndMacro

Macro GetMatrix33Le31(MatrixA)
  
  MatrixA\e31
  
EndMacro

Macro GetMatrix33Le32(MatrixA)
  
  MatrixA\e32
  
EndMacro

Macro GetMatrix33Le33(MatrixA)
  
  MatrixA\e33
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs ligne par ligne <<<<<

Macro SetMatrix33LLine1(MatrixA, P_e11, P_e12, P_e13)
  
  SetMatrix33Le11(MatrixA, P_e11)
  SetMatrix33Le12(MatrixA, P_e12)
  SetMatrix33Le13(MatrixA, P_e13)
  
EndMacro

Macro SetMatrix33LLine2(MatrixA, P_e21, P_e22, P_e23)
  
  SetMatrix33Le21(MatrixA, P_e21)
  SetMatrix33Le22(MatrixA, P_e22)
  SetMatrix33Le23(MatrixA, P_e23)
  
EndMacro

Macro SetMatrix33LLine3(MatrixA, P_e31, P_e32, P_e33)
  
  SetMatrix33Le31(MatrixA, P_e31)
  SetMatrix33Le32(MatrixA, P_e32)
  SetMatrix33Le33(MatrixA, P_e33)
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Product Matrix Vector : R = A * B <<<<<

Macro ProductMatrix33LVector3L(VectorR, MatrixA, VectorB)

  SetVector3Li(VectorR, GetMatrix33Le11(MatrixA) * GetVector3Li(VectorB) + GetMatrix33Le12(MatrixA) * GetVector3Lj(VectorB) + GetMatrix33Le13(MatrixA) * GetVector3Lk(VectorB))
  SetVector3Lj(VectorR, GetMatrix33Le21(MatrixA) * GetVector3Li(VectorB) + GetMatrix33Le22(MatrixA) * GetVector3Lj(VectorB) + GetMatrix33Le23(MatrixA) * GetVector3Lk(VectorB))
  SetVector3Lk(VectorR, GetMatrix33Le31(MatrixA) * GetVector3Li(VectorB) + GetMatrix33Le32(MatrixA) * GetVector3Lj(VectorB) + GetMatrix33Le33(MatrixA) * GetVector3Lk(VectorB))
  
EndMacro 

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< ReadEncodedString <<<<<

ProcedureDLL.s ReadEncodedString(FileID.l)
  
  Inverse.Matrix33L
  VectorCoded.Vector3L
  VectorDecoded.Vector3L
  
  MatrixID.b = ReadByte(FileID)
  
  Select MatrixID
      
    Case 0
      
      SetMatrix33LLine1(Inverse, -7, -12, 14)
      SetMatrix33LLine2(Inverse, 3, 5, -6)
      SetMatrix33LLine3(Inverse, 31, 54, -63)
      
    Case 1
      
      SetMatrix33LLine1(Inverse, -24, -47, -33)
      SetMatrix33LLine2(Inverse, 2, 4, 3)
      SetMatrix33LLine3(Inverse, 19, 37, 26)
      
    Case 2
      
      SetMatrix33LLine1(Inverse, -30, -39, -22)
      SetMatrix33LLine2(Inverse, 23, 30, 17)
      SetMatrix33LLine3(Inverse, -19, -25, -14)
      
    Case 3
      
      SetMatrix33LLine1(Inverse, 1, -13, 11)
      SetMatrix33LLine2(Inverse, 1, -18, 15)
      SetMatrix33LLine3(Inverse, -1, 17, -14)
      
    Case 4
      
      SetMatrix33LLine1(Inverse, -3, -1, 2)
      SetMatrix33LLine2(Inverse, -10, -3, 7)
      SetMatrix33LLine3(Inverse, -42, -13, 30)
      
    Case 5
      
      SetMatrix33LLine1(Inverse, 3, -3, 5)
      SetMatrix33LLine2(Inverse, -14, 13, -21)
      SetMatrix33LLine3(Inverse, 5, -5, 8)
      
    Case 6
      
      SetMatrix33LLine1(Inverse, -77, -83, 25)
      SetMatrix33LLine2(Inverse, -65, -70, 21)
      SetMatrix33LLine3(Inverse, 40, 43, -13)
      
    Case 7
      
      SetMatrix33LLine1(Inverse, 35, -96, -73)
      SetMatrix33LLine2(Inverse, -3, 8, 6)
      SetMatrix33LLine3(Inverse, 12, -33, -25)
      
    Case 8
      
      SetMatrix33LLine1(Inverse, 54, 29, -63)
      SetMatrix33LLine2(Inverse, -24, -13, 28)
      SetMatrix33LLine3(Inverse, -13, -7, 15)
      
    Case 9
      
      SetMatrix33LLine1(Inverse, 5, 27, -34)
      SetMatrix33LLine2(Inverse, 0, 1, -1)
      SetMatrix33LLine3(Inverse, 3, 15, -19)
      
    Case 10
      
      SetMatrix33LLine1(Inverse, 0, 1, -1)
      SetMatrix33LLine2(Inverse, 1, -54, 49)
      SetMatrix33LLine3(Inverse, 0, 9, -8)
      
    Case 11
      
      SetMatrix33LLine1(Inverse, 3, -25, 51)
      SetMatrix33LLine2(Inverse, 3, -26, 53)
      SetMatrix33LLine3(Inverse, -4, 34, -69)
      
    Case 12
      
      SetMatrix33LLine1(Inverse, 18, -13, -2)
      SetMatrix33LLine2(Inverse, 69, -50, -8)
      SetMatrix33LLine3(Inverse, -113, 82, 13)
      
  EndSelect 
  
  MaxChar.l = ReadLong(FileID)
  
  For Index = 0 To MaxChar - 1 Step 3
    
    ReadVector3L(FileID, VectorCoded)
    ProductMatrix33LVector3L(VectorDecoded, Inverse, VectorCoded)
    String.s = String + Chr(GetVector3Li(VectorDecoded)) + Chr(GetVector3Lj(VectorDecoded)) + Chr(GetVector3Lk(VectorDecoded))
    
  Next
  
  ProcedureReturn String
EndProcedure
    
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< WriteEncodedString <<<<<
    
ProcedureDLL WriteEncodedString(FileID.l, String.s)
  
  Matrix.Matrix33L
  VectorCoded.Vector3L
  VectorDecoded.Vector3L
  
  MatrixID = Random(12)
  
  Select MatrixID
      
    Case 0
      
      SetMatrix33LLine1(Matrix, -9, 0, -2)
      SetMatrix33LLine2(Matrix, -3, -7, 0)
      SetMatrix33LLine3(Matrix, -7, -6, -1)
      
    Case 1
      
      SetMatrix33LLine1(Matrix, 7, -1, 9)
      SetMatrix33LLine2(Matrix, -5, -3, -6)
      SetMatrix33LLine3(Matrix, 2, 5, 2)
      
    Case 2
      
      SetMatrix33LLine1(Matrix, -5, -4, 3)
      SetMatrix33LLine2(Matrix, 1, -2, -4)
      SetMatrix33LLine3(Matrix, 5, 9, 3)
      
    Case 3
      
      SetMatrix33LLine1(Matrix, 3, -5, -3)
      SetMatrix33LLine2(Matrix, 1, 3, 4)
      SetMatrix33LLine3(Matrix, 1, 4, 5)
      
    Case 4
      
      SetMatrix33LLine1(Matrix, -1, -4, 1)
      SetMatrix33LLine2(Matrix, -6, 6, -1)
      SetMatrix33LLine3(Matrix, -4, -3, 1)
      
    Case 5
      
      SetMatrix33LLine1(Matrix, -1, -1, -2)
      SetMatrix33LLine2(Matrix, 7, -1, -7)
      SetMatrix33LLine3(Matrix, 5, 0, -3)
      
    Case 6
      
      SetMatrix33LLine1(Matrix, 7, -4, 7)
      SetMatrix33LLine2(Matrix, -5, 1, -8)
      SetMatrix33LLine3(Matrix, 5, -9, -5)
      
    Case 7
      
      SetMatrix33LLine1(Matrix, 2, -9, -8)
      SetMatrix33LLine2(Matrix, 3, -1, -9)
      SetMatrix33LLine3(Matrix, -3, -3, 8)
      
    Case 8
      
      SetMatrix33LLine1(Matrix, 1, 6, -7)
      SetMatrix33LLine2(Matrix, -4, -9, 0)
      SetMatrix33LLine3(Matrix, -1, 1, -6)
      
    Case 9
      
      SetMatrix33LLine1(Matrix, -4, 3, 7)
      SetMatrix33LLine2(Matrix, -3, 7, 5)
      SetMatrix33LLine3(Matrix, -3, 6, 5)
      
    Case 10
      
      SetMatrix33LLine1(Matrix, 9, 1, 5)
      SetMatrix33LLine2(Matrix, -8, 0, 1)
      SetMatrix33LLine3(Matrix, -9, 0, 1)
      
    Case 11
      
      SetMatrix33LLine1(Matrix, 8, -9, -1)
      SetMatrix33LLine2(Matrix, 5, 3, 6)
      SetMatrix33LLine3(Matrix, 2, 2, 3)
      
    Case 12
      
      SetMatrix33LLine1(Matrix, 6, 5, 4)
      SetMatrix33LLine2(Matrix, 7, 8, 6)
      SetMatrix33LLine3(Matrix, 8, -7, -3)
      
  EndSelect 
  
  WriteByte(FileID, MatrixID)
  MaxChar.l = Len(String)
  WriteLong(FileID, MaxChar)
  
  For Index = 0 To MaxChar - 1 Step 3
    
    SetVector3Li(VectorDecoded, Asc(Mid(String, Index + 1, 1)))
    SetVector3Lj(VectorDecoded, Asc(Mid(String, Index + 2, 1)))
    SetVector3Lk(VectorDecoded, Asc(Mid(String, Index + 3, 1)))
    
    ProductMatrix33LVector3L(VectorCoded, Matrix, VectorDecoded)
    WriteVector3L(FileID, VectorCoded)
    
  Next
  
EndProcedure
    
; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< CODE D'ESSAI <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<

Dim Texte.s(10)

Texte(0) = "Allô le monde !"
Texte(1) = "Comment ça va ?"
Texte(2) = "Ca va super bien, et vous ?"
Texte(3) = "Ça va pas pire du tout."
Texte(4) = "Test d'une nouvelle version de EncodedString."
Texte(5) = "PureBasic it's the best of the best."
Texte(6) = "Jeudi 7 août 2008"
Texte(7) = "Atlantis"
Texte(8) = "C'est les vacances !"
Texte(9) = "J'aime les belles filles, spécialement les déesses nordiques !"
Texte(10) = "C'est la fin des vacances, noooonnnnn !"

If CreateFile(0, "TestEncodedString.dat")
  
  For Index = 0 To 10
    WriteEncodedString(0, Texte(Index))
  Next
 
  CloseFile(0)
EndIf

If ReadFile(1, "TestEncodedString.dat")
  
  For Index = 0 To 10
    Debug ReadEncodedString(1)
  Next
  
  CloseFile(1)
EndIf

; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<< 
A+
Guimauve
Anonyme

Message par Anonyme »

C'est très intéressant , au niveau du poids de sortie tu connais le ratio ?
sur des gros fichier , l'encodage peut être volumineux ?
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Message par Guimauve »

Cpl.Bator a écrit :C'est très intéressant , au niveau du poids de sortie tu connais le ratio ?
sur des gros fichier , l'encodage peut être volumineux ?
Je n'ai pas étudier cet aspect cependant il n'y a aucune limite à propos de la longueur de la chaîne de caractère pouvant être encoder avec ce système.

À propos de la grosseur du fichier généré, sa taille correspond à la taille d'un entier long par le nombre de caractère de la chaîne.

--> 4 octets X Nb Caractère
--> 4 octets X 1000 Caractères = 4000 octets (4 ko)

Je pense qu'il est possible de réduire la taille du fichier en utilisant le type Word (.w) au lieu de Long (.l) dans la structure Vector3L. Je vais faire des tests à ce sujet d'ici demain.

A+
Guimauve
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Message par Guimauve »

J'ai fait quelques test et l'utilisation du type word (.w) ne pose pas de problème. Je redonne la version corrigé afin de comparer avec la version précédente.

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Read\Write EncodedString
; Nom du fichier : Lib_EncodedString.pb
; Version du fichier : 2.0.0
; Programmation : OK
; Programmé par : Guimauve
; Date : 07-08-2008
; Mise à jour : 30-08-2008
; Codé pour PureBasic V4.20
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration de la Structure <<<<<

Structure Vector3W
  
  i.w
  j.w
  k.w
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<

Macro SetVector3Wi(VectorA, P_i)
  
  VectorA\i = P_i
  
EndMacro

Macro SetVector3Wj(VectorA, P_j)
  
  VectorA\j = P_j
  
EndMacro

Macro SetVector3Wk(VectorA, P_k)
  
  VectorA\k = P_k
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<

Macro GetVector3Wi(VectorA)
  
  VectorA\i
  
EndMacro

Macro GetVector3Wj(VectorA)
  
  VectorA\j
  
EndMacro

Macro GetVector3Wk(VectorA)
  
  VectorA\k
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Lecture fichier Binaire <<<<<

Macro ReadVector3W(FileID, VectorA)
  
  ReadData(FileID, VectorA, SizeOf(Vector3W))
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Écriture fichier Binaire <<<<<

Macro WriteVector3W(FileID, VectorA)
  
  WriteData(FileID, VectorA, SizeOf(Vector3W))
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Déclaration de la Structure <<<<<

Structure Matrix33W
  
  e11.w
  e12.w
  e13.w
  e21.w
  e22.w
  e23.w
  e31.w
  e32.w
  e33.w
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs <<<<<

Macro SetMatrix33We11(MatrixA, P_e11)
  
  MatrixA\e11 = P_e11
  
EndMacro

Macro SetMatrix33We12(MatrixA, P_e12)
  
  MatrixA\e12 = P_e12
  
EndMacro

Macro SetMatrix33We13(MatrixA, P_e13)
  
  MatrixA\e13 = P_e13
  
EndMacro

Macro SetMatrix33We21(MatrixA, P_e21)
  
  MatrixA\e21 = P_e21
  
EndMacro

Macro SetMatrix33We22(MatrixA, P_e22)
  
  MatrixA\e22 = P_e22
  
EndMacro

Macro SetMatrix33We23(MatrixA, P_e23)
  
  MatrixA\e23 = P_e23
  
EndMacro

Macro SetMatrix33We31(MatrixA, P_e31)
  
  MatrixA\e31 = P_e31
  
EndMacro

Macro SetMatrix33We32(MatrixA, P_e32)
  
  MatrixA\e32 = P_e32
  
EndMacro

Macro SetMatrix33We33(MatrixA, P_e33)
  
  MatrixA\e33 = P_e33
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les observateurs <<<<<

Macro GetMatrix33We11(MatrixA)
  
  MatrixA\e11
  
EndMacro

Macro GetMatrix33We12(MatrixA)
  
  MatrixA\e12
  
EndMacro

Macro GetMatrix33We13(MatrixA)
  
  MatrixA\e13
  
EndMacro

Macro GetMatrix33We21(MatrixA)
  
  MatrixA\e21
  
EndMacro

Macro GetMatrix33We22(MatrixA)
  
  MatrixA\e22
  
EndMacro

Macro GetMatrix33We23(MatrixA)
  
  MatrixA\e23
  
EndMacro

Macro GetMatrix33We31(MatrixA)
  
  MatrixA\e31
  
EndMacro

Macro GetMatrix33We32(MatrixA)
  
  MatrixA\e32
  
EndMacro

Macro GetMatrix33We33(MatrixA)
  
  MatrixA\e33
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Les mutateurs ligne par ligne <<<<<

Macro SetMatrix33WLine1(MatrixA, P_e11, P_e12, P_e13)
  
  SetMatrix33We11(MatrixA, P_e11)
  SetMatrix33We12(MatrixA, P_e12)
  SetMatrix33We13(MatrixA, P_e13)
  
EndMacro

Macro SetMatrix33WLine2(MatrixA, P_e21, P_e22, P_e23)
  
  SetMatrix33We21(MatrixA, P_e21)
  SetMatrix33We22(MatrixA, P_e22)
  SetMatrix33We23(MatrixA, P_e23)
  
EndMacro

Macro SetMatrix33WLine3(MatrixA, P_e31, P_e32, P_e33)
  
  SetMatrix33We31(MatrixA, P_e31)
  SetMatrix33We32(MatrixA, P_e32)
  SetMatrix33We33(MatrixA, P_e33)
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< L'opérateur Product Matrix Vector : R = A * B <<<<<

Macro ProductMatrix33WVector3W(VectorR, MatrixA, VectorB)

  SetVector3Wi(VectorR, GetMatrix33We11(MatrixA) * GetVector3Wi(VectorB) + GetMatrix33We12(MatrixA) * GetVector3Wj(VectorB) + GetMatrix33We13(MatrixA) * GetVector3Wk(VectorB))
  SetVector3Wj(VectorR, GetMatrix33We21(MatrixA) * GetVector3Wi(VectorB) + GetMatrix33We22(MatrixA) * GetVector3Wj(VectorB) + GetMatrix33We23(MatrixA) * GetVector3Wk(VectorB))
  SetVector3Wk(VectorR, GetMatrix33We31(MatrixA) * GetVector3Wi(VectorB) + GetMatrix33We32(MatrixA) * GetVector3Wj(VectorB) + GetMatrix33We33(MatrixA) * GetVector3Wk(VectorB))
  
EndMacro 

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< ReadEncodedString <<<<<

ProcedureDLL.s ReadEncodedString(FileID.l)
  
  Inverse.Matrix33W
  VectorCoded.Vector3W
  VectorDecoded.Vector3W
  
  MatrixID.b = ReadByte(FileID)
  
  Select MatrixID
      
    Case 0
      
      SetMatrix33WLine1(Inverse, -7, -12, 14)
      SetMatrix33WLine2(Inverse, 3, 5, -6)
      SetMatrix33WLine3(Inverse, 31, 54, -63)
      
    Case 1
      
      SetMatrix33WLine1(Inverse, -24, -47, -33)
      SetMatrix33WLine2(Inverse, 2, 4, 3)
      SetMatrix33WLine3(Inverse, 19, 37, 26)
      
    Case 2
      
      SetMatrix33WLine1(Inverse, -30, -39, -22)
      SetMatrix33WLine2(Inverse, 23, 30, 17)
      SetMatrix33WLine3(Inverse, -19, -25, -14)
      
    Case 3
      
      SetMatrix33WLine1(Inverse, 1, -13, 11)
      SetMatrix33WLine2(Inverse, 1, -18, 15)
      SetMatrix33WLine3(Inverse, -1, 17, -14)
      
    Case 4
      
      SetMatrix33WLine1(Inverse, -3, -1, 2)
      SetMatrix33WLine2(Inverse, -10, -3, 7)
      SetMatrix33WLine3(Inverse, -42, -13, 30)
      
    Case 5
      
      SetMatrix33WLine1(Inverse, 3, -3, 5)
      SetMatrix33WLine2(Inverse, -14, 13, -21)
      SetMatrix33WLine3(Inverse, 5, -5, 8)
      
    Case 6
      
      SetMatrix33WLine1(Inverse, -77, -83, 25)
      SetMatrix33WLine2(Inverse, -65, -70, 21)
      SetMatrix33WLine3(Inverse, 40, 43, -13)
      
    Case 7
      
      SetMatrix33WLine1(Inverse, 35, -96, -73)
      SetMatrix33WLine2(Inverse, -3, 8, 6)
      SetMatrix33WLine3(Inverse, 12, -33, -25)
      
    Case 8
      
      SetMatrix33WLine1(Inverse, 54, 29, -63)
      SetMatrix33WLine2(Inverse, -24, -13, 28)
      SetMatrix33WLine3(Inverse, -13, -7, 15)
      
    Case 9
      
      SetMatrix33WLine1(Inverse, 5, 27, -34)
      SetMatrix33WLine2(Inverse, 0, 1, -1)
      SetMatrix33WLine3(Inverse, 3, 15, -19)
      
    Case 10
      
      SetMatrix33WLine1(Inverse, 0, 1, -1)
      SetMatrix33WLine2(Inverse, 1, -54, 49)
      SetMatrix33WLine3(Inverse, 0, 9, -8)
      
    Case 11
      
      SetMatrix33WLine1(Inverse, 3, -25, 51)
      SetMatrix33WLine2(Inverse, 3, -26, 53)
      SetMatrix33WLine3(Inverse, -4, 34, -69)
      
    Case 12
      
      SetMatrix33WLine1(Inverse, 18, -13, -2)
      SetMatrix33WLine2(Inverse, 69, -50, -8)
      SetMatrix33WLine3(Inverse, -113, 82, 13)
      
  EndSelect 
  
  MaxChar.l = ReadLong(FileID)
  
  For Index = 0 To MaxChar - 1 Step 3
    
    ReadVector3W(FileID, VectorCoded)
    ProductMatrix33WVector3W(VectorDecoded, Inverse, VectorCoded)
    String.s = String + Chr(GetVector3Wi(VectorDecoded)) + Chr(GetVector3Wj(VectorDecoded)) + Chr(GetVector3Wk(VectorDecoded))
    
  Next
  
  ProcedureReturn String
EndProcedure
    
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< WriteEncodedString <<<<<
    
ProcedureDLL WriteEncodedString(FileID.l, String.s)
  
  Matrix.Matrix33W
  VectorCoded.Vector3W
  VectorDecoded.Vector3W
  
  MatrixID = Random(12)
  
  Select MatrixID
      
    Case 0
      
      SetMatrix33WLine1(Matrix, -9, 0, -2)
      SetMatrix33WLine2(Matrix, -3, -7, 0)
      SetMatrix33WLine3(Matrix, -7, -6, -1)
      
    Case 1
      
      SetMatrix33WLine1(Matrix, 7, -1, 9)
      SetMatrix33WLine2(Matrix, -5, -3, -6)
      SetMatrix33WLine3(Matrix, 2, 5, 2)
      
    Case 2
      
      SetMatrix33WLine1(Matrix, -5, -4, 3)
      SetMatrix33WLine2(Matrix, 1, -2, -4)
      SetMatrix33WLine3(Matrix, 5, 9, 3)
      
    Case 3
      
      SetMatrix33WLine1(Matrix, 3, -5, -3)
      SetMatrix33WLine2(Matrix, 1, 3, 4)
      SetMatrix33WLine3(Matrix, 1, 4, 5)
      
    Case 4
      
      SetMatrix33WLine1(Matrix, -1, -4, 1)
      SetMatrix33WLine2(Matrix, -6, 6, -1)
      SetMatrix33WLine3(Matrix, -4, -3, 1)
      
    Case 5
      
      SetMatrix33WLine1(Matrix, -1, -1, -2)
      SetMatrix33WLine2(Matrix, 7, -1, -7)
      SetMatrix33WLine3(Matrix, 5, 0, -3)
      
    Case 6
      
      SetMatrix33WLine1(Matrix, 7, -4, 7)
      SetMatrix33WLine2(Matrix, -5, 1, -8)
      SetMatrix33WLine3(Matrix, 5, -9, -5)
      
    Case 7
      
      SetMatrix33WLine1(Matrix, 2, -9, -8)
      SetMatrix33WLine2(Matrix, 3, -1, -9)
      SetMatrix33WLine3(Matrix, -3, -3, 8)
      
    Case 8
      
      SetMatrix33WLine1(Matrix, 1, 6, -7)
      SetMatrix33WLine2(Matrix, -4, -9, 0)
      SetMatrix33WLine3(Matrix, -1, 1, -6)
      
    Case 9
      
      SetMatrix33WLine1(Matrix, -4, 3, 7)
      SetMatrix33WLine2(Matrix, -3, 7, 5)
      SetMatrix33WLine3(Matrix, -3, 6, 5)
      
    Case 10
      
      SetMatrix33WLine1(Matrix, 9, 1, 5)
      SetMatrix33WLine2(Matrix, -8, 0, 1)
      SetMatrix33WLine3(Matrix, -9, 0, 1)
      
    Case 11
      
      SetMatrix33WLine1(Matrix, 8, -9, -1)
      SetMatrix33WLine2(Matrix, 5, 3, 6)
      SetMatrix33WLine3(Matrix, 2, 2, 3)
      
    Case 12
      
      SetMatrix33WLine1(Matrix, 6, 5, 4)
      SetMatrix33WLine2(Matrix, 7, 8, 6)
      SetMatrix33WLine3(Matrix, 8, -7, -3)
      
  EndSelect 
  
  WriteByte(FileID, MatrixID)
  MaxChar.l = Len(String)
  WriteLong(FileID, MaxChar)
  
  For Index = 0 To MaxChar - 1 Step 3
    
    SetVector3Wi(VectorDecoded, Asc(Mid(String, Index + 1, 1)))
    SetVector3Wj(VectorDecoded, Asc(Mid(String, Index + 2, 1)))
    SetVector3Wk(VectorDecoded, Asc(Mid(String, Index + 3, 1)))
    
    ProductMatrix33WVector3W(VectorCoded, Matrix, VectorDecoded)
    WriteVector3W(FileID, VectorCoded)
    
  Next
  
EndProcedure
    
; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< CODE D'ESSAI <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<

Dim Texte.s(10)

Texte(0) = "Allô le monde !"
Texte(1) = "Comment ça va ?"
Texte(2) = "Ca va super bien, et vous ?"
Texte(3) = "Ça va pas pire du tout."
Texte(4) = "Test d'une nouvelle version de EncodedString."
Texte(5) = "PureBasic it's the best of the best."
Texte(6) = "Jeudi 7 août 2008"
Texte(7) = "Atlantis"
Texte(8) = "C'est les vacances !"
Texte(9) = "J'aime les belles filles, spécialement les déesses nordiques !"
Texte(10) = "ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ"

If CreateFile(0, "TestEncodedString.dat")
  
  For Index = 0 To 10
    WriteEncodedString(0, Texte(Index))
  Next
 
  CloseFile(0)
EndIf

If ReadFile(1, "TestEncodedString.dat")
  
  For Index = 0 To 10
    Debug ReadEncodedString(1)
  Next
  Debug "La taille du fichier : " + Str(Lof(1)) + " octets"
  CloseFile(1)
EndIf

; <<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< FIN DU FICHIER <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<
Le calcul de la taille du fichier donne :

--> 2 octets X Nb Caractère
--> 2 octets X 1000 Caractères = 2000 octets (2 ko)

Personnellement, j'aimerais bien voir ces 2 commandes apparaître en natif...

Depuis leurs créations je n'ai plus jamais utilisé celles-ci :

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Nom du projet : Read & Write Binary String
; Nom du fichier : Lib_BinaryString.pb
; Version : 1.0.0
; Programmation : OK
; Programmé par : Guimauve
; Date : 24-03-2006
; Mise à jour : 24-03-2006
; Codé avec PureBasic V4.00
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

ProcedureDLL WriteBinaryString(FileID, String.s)

  length.l = Len(String)
  WriteLong(FileID, length)
  WriteData(FileID, @String, length)

EndProcedure 

ProcedureDLL.s ReadBinaryString(FileID)

  length.l = ReadLong(FileID)
  String.s = Space(length)
  ReadData(FileID, @String, length)

  ProcedureReturn String
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<< FIN DU FICHIER <<<<
; <<<<<<<<<<<<<<<<<<<<<<<<
A+
Guimauve
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Message par Guimauve »

Bonjour à tous,

Un petit supplément à la précédente librairie. Cette fois on manipule des blocs mémoires. J'ai ajouté ces deux commandes afin d'avoir la chance d'encoder le nom des fichiers compressés à l'aide de la librairie Packer.

Si vous avez besoin d'un exemple il suffit de me demander.

A+
Guimauve

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< PeekEncodedString <<<<<
  
ProcedureDLL.s PeekEncodedString(MemoryBuffer)
  
  Inverse.Matrix33W
  VectorDecoded.Vector3W
  
  MatrixID.b = PeekB(MemoryBuffer)
  
  Select MatrixID
      
    Case 0
      
      SetMatrix33WLine1(Inverse, -7, -12, 14)
      SetMatrix33WLine2(Inverse, 3, 5, -6)
      SetMatrix33WLine3(Inverse, 31, 54, -63)
      
    Case 1
      
      SetMatrix33WLine1(Inverse, -24, -47, -33)
      SetMatrix33WLine2(Inverse, 2, 4, 3)
      SetMatrix33WLine3(Inverse, 19, 37, 26)
      
    Case 2
      
      SetMatrix33WLine1(Inverse, -30, -39, -22)
      SetMatrix33WLine2(Inverse, 23, 30, 17)
      SetMatrix33WLine3(Inverse, -19, -25, -14)
      
    Case 3
      
      SetMatrix33WLine1(Inverse, 1, -13, 11)
      SetMatrix33WLine2(Inverse, 1, -18, 15)
      SetMatrix33WLine3(Inverse, -1, 17, -14)
      
    Case 4
      
      SetMatrix33WLine1(Inverse, -3, -1, 2)
      SetMatrix33WLine2(Inverse, -10, -3, 7)
      SetMatrix33WLine3(Inverse, -42, -13, 30)
      
    Case 5
      
      SetMatrix33WLine1(Inverse, 3, -3, 5)
      SetMatrix33WLine2(Inverse, -14, 13, -21)
      SetMatrix33WLine3(Inverse, 5, -5, 8)
      
    Case 6
      
      SetMatrix33WLine1(Inverse, -77, -83, 25)
      SetMatrix33WLine2(Inverse, -65, -70, 21)
      SetMatrix33WLine3(Inverse, 40, 43, -13)
      
    Case 7
      
      SetMatrix33WLine1(Inverse, 35, -96, -73)
      SetMatrix33WLine2(Inverse, -3, 8, 6)
      SetMatrix33WLine3(Inverse, 12, -33, -25)
      
    Case 8
      
      SetMatrix33WLine1(Inverse, 54, 29, -63)
      SetMatrix33WLine2(Inverse, -24, -13, 28)
      SetMatrix33WLine3(Inverse, -13, -7, 15)
      
    Case 9
      
      SetMatrix33WLine1(Inverse, 5, 27, -34)
      SetMatrix33WLine2(Inverse, 0, 1, -1)
      SetMatrix33WLine3(Inverse, 3, 15, -19)
      
    Case 10
      
      SetMatrix33WLine1(Inverse, 0, 1, -1)
      SetMatrix33WLine2(Inverse, 1, -54, 49)
      SetMatrix33WLine3(Inverse, 0, 9, -8)
      
    Case 11
      
      SetMatrix33WLine1(Inverse, 3, -25, 51)
      SetMatrix33WLine2(Inverse, 3, -26, 53)
      SetMatrix33WLine3(Inverse, -4, 34, -69)
      
    Case 12
      
      SetMatrix33WLine1(Inverse, 18, -13, -2)
      SetMatrix33WLine2(Inverse, 69, -50, -8)
      SetMatrix33WLine3(Inverse, -113, 82, 13)
      
  EndSelect 
  
  MaxChar.l = PeekL(MemoryBuffer + SizeOf(Byte))
  *VectorCoded.Vector3W = MemoryBuffer + SizeOf(Byte) + SizeOf(Long)
  
  For Index = 0 To MaxChar - 1 Step 3
    
    ProductMatrix33WVector3W(VectorDecoded, Inverse, *VectorCoded)
    String.s = String + Chr(GetVector3Wi(VectorDecoded)) + Chr(GetVector3Wj(VectorDecoded)) + Chr(GetVector3Wk(VectorDecoded))
    *VectorCoded + SizeOf(Vector3W)
    
  Next
  
  ProcedureReturn String
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< PokeEncodedString <<<<<

ProcedureDLL PokeEncodedString(String.s)
  
  Matrix.Matrix33W
  VectorDecoded.Vector3W
  
  MatrixID = Random(12)
  
  Select MatrixID
      
    Case 0
      
      SetMatrix33WLine1(Matrix, -9, 0, -2)
      SetMatrix33WLine2(Matrix, -3, -7, 0)
      SetMatrix33WLine3(Matrix, -7, -6, -1)
      
    Case 1
      
      SetMatrix33WLine1(Matrix, 7, -1, 9)
      SetMatrix33WLine2(Matrix, -5, -3, -6)
      SetMatrix33WLine3(Matrix, 2, 5, 2)
      
    Case 2
      
      SetMatrix33WLine1(Matrix, -5, -4, 3)
      SetMatrix33WLine2(Matrix, 1, -2, -4)
      SetMatrix33WLine3(Matrix, 5, 9, 3)
      
    Case 3
      
      SetMatrix33WLine1(Matrix, 3, -5, -3)
      SetMatrix33WLine2(Matrix, 1, 3, 4)
      SetMatrix33WLine3(Matrix, 1, 4, 5)
      
    Case 4
      
      SetMatrix33WLine1(Matrix, -1, -4, 1)
      SetMatrix33WLine2(Matrix, -6, 6, -1)
      SetMatrix33WLine3(Matrix, -4, -3, 1)
      
    Case 5
      
      SetMatrix33WLine1(Matrix, -1, -1, -2)
      SetMatrix33WLine2(Matrix, 7, -1, -7)
      SetMatrix33WLine3(Matrix, 5, 0, -3)
      
    Case 6
      
      SetMatrix33WLine1(Matrix, 7, -4, 7)
      SetMatrix33WLine2(Matrix, -5, 1, -8)
      SetMatrix33WLine3(Matrix, 5, -9, -5)
      
    Case 7
      
      SetMatrix33WLine1(Matrix, 2, -9, -8)
      SetMatrix33WLine2(Matrix, 3, -1, -9)
      SetMatrix33WLine3(Matrix, -3, -3, 8)
      
    Case 8
      
      SetMatrix33WLine1(Matrix, 1, 6, -7)
      SetMatrix33WLine2(Matrix, -4, -9, 0)
      SetMatrix33WLine3(Matrix, -1, 1, -6)
      
    Case 9
      
      SetMatrix33WLine1(Matrix, -4, 3, 7)
      SetMatrix33WLine2(Matrix, -3, 7, 5)
      SetMatrix33WLine3(Matrix, -3, 6, 5)
      
    Case 10
      
      SetMatrix33WLine1(Matrix, 9, 1, 5)
      SetMatrix33WLine2(Matrix, -8, 0, 1)
      SetMatrix33WLine3(Matrix, -9, 0, 1)
      
    Case 11
      
      SetMatrix33WLine1(Matrix, 8, -9, -1)
      SetMatrix33WLine2(Matrix, 5, 3, 6)
      SetMatrix33WLine3(Matrix, 2, 2, 3)
      
    Case 12
      
      SetMatrix33WLine1(Matrix, 6, 5, 4)
      SetMatrix33WLine2(Matrix, 7, 8, 6)
      SetMatrix33WLine3(Matrix, 8, -7, -3)
      
  EndSelect 
  
  MaxChar.l = Len(String)
  Len = MaxChar
  Reste = Len % 3
  
  While Reste 
    
    Len = Len + 1
    Reste = Len % 3
    
  Wend
  
  MemoryBuffer = AllocateMemory(SizeOf(Byte) + SizeOf(Long) + Len * SizeOf(Word))
  
  PokeB(MemoryBuffer, MatrixID)
  PokeL(MemoryBuffer + SizeOf(Byte), MaxChar)
  
  *VectorCoded.Vector3W = MemoryBuffer + SizeOf(Byte) + SizeOf(Long)
  
  For Index = 0 To MaxChar - 1 Step 3
    
    SetVector3Wi(VectorDecoded, Asc(Mid(String, Index + 1, 1)))
    SetVector3Wj(VectorDecoded, Asc(Mid(String, Index + 2, 1)))
    SetVector3Wk(VectorDecoded, Asc(Mid(String, Index + 3, 1)))
    ProductMatrix33WVector3W(*VectorCoded, Matrix, VectorDecoded)
    *VectorCoded + SizeOf(Vector3W)
    
  Next
  
  ProcedureReturn MemoryBuffer
EndProcedure
Répondre