Page 1 of 1

Read\Write EncodedString - New Version

Posted: Fri Aug 29, 2008 2:36 pm
by Guimauve
Hello everyone,

I have created two small procedures to Read and Write string on binary file using ASCII code and Matrices calculations. Have fun !

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; 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

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< 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 <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<< 
Regards
Guimauve

Posted: Sat May 30, 2009 2:01 pm
by Guimauve
Hello everyone

This is a new version of my Read/Write Encoded String lib. I have also included the Read/Write Binary String in this lib.

Have Fun !

Guimauve

The lib File :

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Read/Write Binary/Encoded String
; File : Read_Write_Binary_Encoded_String.pb
; File Version : 3.0.0
; Programmation : OK
; Programmed by : Guimauve
; Date : 30-05-2009
; Last Update : 30-05-2009
; Coded for PureBasic V4.30
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Structure declaration <<<<<

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

; <<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The observators <<<<<

Macro GetVector3Li(VectorA)
  
  VectorA\i
  
EndMacro

Macro GetVector3Lj(VectorA)
  
  VectorA\j
  
EndMacro

Macro GetVector3Lk(VectorA)
  
  VectorA\k
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The mutators <<<<<

Macro SetVector3Li(VectorA, P_i)
  
  GetVector3Li(VectorA) = P_i
  
EndMacro

Macro SetVector3Lj(VectorA, P_j)
  
  GetVector3Lj(VectorA) = P_j
  
EndMacro

Macro SetVector3Lk(VectorA, P_k)
  
  GetVector3Lk(VectorA) = P_k
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Read binary file operator <<<<<

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

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Write binary file operator <<<<<

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

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Structure declaration <<<<<

Structure Vector4L
  
  i.l
  j.l
  k.l
  l.l
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The observators <<<<<

Macro GetVector4Li(VectorA)
  
  VectorA\i
  
EndMacro

Macro GetVector4Lj(VectorA)
  
  VectorA\j
  
EndMacro

Macro GetVector4Lk(VectorA)
  
  VectorA\k
  
EndMacro

Macro GetVector4Ll(VectorA)
  
  VectorA\l
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The mutators <<<<<

Macro SetVector4Li(VectorA, P_i)
  
  GetVector4Li(VectorA) = P_i
  
EndMacro

Macro SetVector4Lj(VectorA, P_j)
  
  GetVector4Lj(VectorA) = P_j
  
EndMacro

Macro SetVector4Lk(VectorA, P_k)
  
  GetVector4Lk(VectorA) = P_k
  
EndMacro

Macro SetVector4Ll(VectorA, P_l)
  
  GetVector4Ll(VectorA) = P_l
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Read binary file operator <<<<<

Macro ReadVector4L(FileID, VectorA)
  
  ReadData(FileID, VectorA, SizeOf(Vector4L))
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Write binary file operator <<<<<

Macro WriteVector4L(FileID, VectorA)
  
  WriteData(FileID, VectorA, SizeOf(Vector4L))
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Structure declaration <<<<<

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

; <<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The observators <<<<<

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

; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The mutators <<<<<

Macro SetMatrix33Le11(MatrixA, P_e11)
  
  GetMatrix33Le11(MatrixA) = P_e11
  
EndMacro

Macro SetMatrix33Le12(MatrixA, P_e12)
  
  GetMatrix33Le12(MatrixA) = P_e12
  
EndMacro

Macro SetMatrix33Le13(MatrixA, P_e13)
  
  GetMatrix33Le13(MatrixA) = P_e13
  
EndMacro

Macro SetMatrix33Le21(MatrixA, P_e21)
  
  GetMatrix33Le21(MatrixA) = P_e21
  
EndMacro

Macro SetMatrix33Le22(MatrixA, P_e22)
  
  GetMatrix33Le22(MatrixA) = P_e22
  
EndMacro

Macro SetMatrix33Le23(MatrixA, P_e23)
  
  GetMatrix33Le23(MatrixA) = P_e23
  
EndMacro

Macro SetMatrix33Le31(MatrixA, P_e31)
  
  GetMatrix33Le31(MatrixA) = P_e31
  
EndMacro

Macro SetMatrix33Le32(MatrixA, P_e32)
  
  GetMatrix33Le32(MatrixA) = P_e32
  
EndMacro

Macro SetMatrix33Le33(MatrixA, P_e33)
  
  GetMatrix33Le33(MatrixA) = P_e33
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The Line by Line Mutators <<<<<

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

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The Product Matrix Vector operator : 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 

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Structure declaration <<<<<

Structure Matrix44L
  
  e11.l
  e21.l
  e31.l
  e41.l
  e12.l
  e22.l
  e32.l
  e42.l
  e13.l
  e23.l
  e33.l
  e43.l
  e14.l
  e24.l
  e34.l
  e44.l
  
EndStructure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The observators <<<<<

Macro GetMatrix44Le11(MatrixA)
  
  MatrixA\e11
  
EndMacro

Macro GetMatrix44Le21(MatrixA)
  
  MatrixA\e21
  
EndMacro

Macro GetMatrix44Le31(MatrixA)
  
  MatrixA\e31
  
EndMacro

Macro GetMatrix44Le41(MatrixA)
  
  MatrixA\e41
  
EndMacro

Macro GetMatrix44Le12(MatrixA)
  
  MatrixA\e12
  
EndMacro

Macro GetMatrix44Le22(MatrixA)
  
  MatrixA\e22
  
EndMacro

Macro GetMatrix44Le32(MatrixA)
  
  MatrixA\e32
  
EndMacro

Macro GetMatrix44Le42(MatrixA)
  
  MatrixA\e42
  
EndMacro

Macro GetMatrix44Le13(MatrixA)
  
  MatrixA\e13
  
EndMacro

Macro GetMatrix44Le23(MatrixA)
  
  MatrixA\e23
  
EndMacro

Macro GetMatrix44Le33(MatrixA)
  
  MatrixA\e33
  
EndMacro

Macro GetMatrix44Le43(MatrixA)
  
  MatrixA\e43
  
EndMacro

Macro GetMatrix44Le14(MatrixA)
  
  MatrixA\e14
  
EndMacro

Macro GetMatrix44Le24(MatrixA)
  
  MatrixA\e24
  
EndMacro

Macro GetMatrix44Le34(MatrixA)
  
  MatrixA\e34
  
EndMacro

Macro GetMatrix44Le44(MatrixA)
  
  MatrixA\e44
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The mutators <<<<<

Macro SetMatrix44Le11(MatrixA, P_e11)
  
  GetMatrix44Le11(MatrixA) = P_e11
  
EndMacro

Macro SetMatrix44Le21(MatrixA, P_e21)
  
  GetMatrix44Le21(MatrixA) = P_e21
  
EndMacro

Macro SetMatrix44Le31(MatrixA, P_e31)
  
  GetMatrix44Le31(MatrixA) = P_e31
  
EndMacro

Macro SetMatrix44Le41(MatrixA, P_e41)
  
  GetMatrix44Le41(MatrixA) = P_e41
  
EndMacro

Macro SetMatrix44Le12(MatrixA, P_e12)
  
  GetMatrix44Le12(MatrixA) = P_e12
  
EndMacro

Macro SetMatrix44Le22(MatrixA, P_e22)
  
  GetMatrix44Le22(MatrixA) = P_e22
  
EndMacro

Macro SetMatrix44Le32(MatrixA, P_e32)
  
  GetMatrix44Le32(MatrixA) = P_e32
  
EndMacro

Macro SetMatrix44Le42(MatrixA, P_e42)
  
  GetMatrix44Le42(MatrixA) = P_e42
  
EndMacro

Macro SetMatrix44Le13(MatrixA, P_e13)
  
  GetMatrix44Le13(MatrixA) = P_e13
  
EndMacro

Macro SetMatrix44Le23(MatrixA, P_e23)
  
  GetMatrix44Le23(MatrixA) = P_e23
  
EndMacro

Macro SetMatrix44Le33(MatrixA, P_e33)
  
  GetMatrix44Le33(MatrixA) = P_e33
  
EndMacro

Macro SetMatrix44Le43(MatrixA, P_e43)
  
  GetMatrix44Le43(MatrixA) = P_e43
  
EndMacro

Macro SetMatrix44Le14(MatrixA, P_e14)
  
  GetMatrix44Le14(MatrixA) = P_e14
  
EndMacro

Macro SetMatrix44Le24(MatrixA, P_e24)
  
  GetMatrix44Le24(MatrixA) = P_e24
  
EndMacro

Macro SetMatrix44Le34(MatrixA, P_e34)
  
  GetMatrix44Le34(MatrixA) = P_e34
  
EndMacro

Macro SetMatrix44Le44(MatrixA, P_e44)
  
  GetMatrix44Le44(MatrixA) = P_e44
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The Line by Line Mutators <<<<<

Macro SetMatrix44LLine1(MatrixA, P_e11, P_e12, P_e13, P_e14)
  
  SetMatrix44Le11(MatrixA, P_e11)
  SetMatrix44Le12(MatrixA, P_e12)
  SetMatrix44Le13(MatrixA, P_e13)
  SetMatrix44Le14(MatrixA, P_e14)
  
EndMacro

Macro SetMatrix44LLine2(MatrixA, P_e21, P_e22, P_e23, P_e24)
  
  SetMatrix44Le21(MatrixA, P_e21)
  SetMatrix44Le22(MatrixA, P_e22)
  SetMatrix44Le23(MatrixA, P_e23)
  SetMatrix44Le24(MatrixA, P_e24)
  
EndMacro

Macro SetMatrix44LLine3(MatrixA, P_e31, P_e32, P_e33, P_e34)
  
  SetMatrix44Le31(MatrixA, P_e31)
  SetMatrix44Le32(MatrixA, P_e32)
  SetMatrix44Le33(MatrixA, P_e33)
  SetMatrix44Le34(MatrixA, P_e34)
  
EndMacro

Macro SetMatrix44LLine4(MatrixA, P_e41, P_e42, P_e43, P_e44)
  
  SetMatrix44Le41(MatrixA, P_e41)
  SetMatrix44Le42(MatrixA, P_e42)
  SetMatrix44Le43(MatrixA, P_e43)
  SetMatrix44Le44(MatrixA, P_e44)
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< The Product Matrix Vector operator : R = A * B <<<<<

Macro ProductMatrix44LVector4L(VectorR, MatrixA, VectorB)
  
  SetVector4Li(VectorR, GetMatrix44Le11(MatrixA) * GetVector4Li(VectorB) + GetMatrix44Le12(MatrixA) * GetVector4Lj(VectorB) + GetMatrix44Le13(MatrixA) * GetVector4Lk(VectorB) + GetMatrix44Le14(MatrixA) * GetVector4Ll(VectorB))
  SetVector4Lj(VectorR, GetMatrix44Le21(MatrixA) * GetVector4Li(VectorB) + GetMatrix44Le22(MatrixA) * GetVector4Lj(VectorB) + GetMatrix44Le23(MatrixA) * GetVector4Lk(VectorB) + GetMatrix44Le24(MatrixA) * GetVector4Ll(VectorB))
  SetVector4Lk(VectorR, GetMatrix44Le31(MatrixA) * GetVector4Li(VectorB) + GetMatrix44Le32(MatrixA) * GetVector4Lj(VectorB) + GetMatrix44Le33(MatrixA) * GetVector4Lk(VectorB) + GetMatrix44Le34(MatrixA) * GetVector4Ll(VectorB))
  SetVector4Ll(VectorR, GetMatrix44Le41(MatrixA) * GetVector4Li(VectorB) + GetMatrix44Le42(MatrixA) * GetVector4Lj(VectorB) + GetMatrix44Le43(MatrixA) * GetVector4Lk(VectorB) + GetMatrix44Le44(MatrixA) * GetVector4Ll(VectorB))
  
EndMacro

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

ProcedureDLL.s ReadEncodedString(FileID.l)
  
  Inverse33.Matrix33L
  VectorCoded3.Vector3L
  VectorDecoded3.Vector3L
  Inverse44.Matrix44L
  VectorCoded4.Vector4L
  VectorDecoded4.Vector4L
  
  MatrixID.b = ReadByte(FileID)
  
  Select MatrixID
      
    Case 0
      SetMatrix33LLine1(Inverse33, -7, -12, 14)
      SetMatrix33LLine2(Inverse33, 3, 5, -6)
      SetMatrix33LLine3(Inverse33, 31, 54, -63)
      MatrixSize.b = 3
      
    Case 1
      SetMatrix33LLine1(Inverse33, -24, -47, -33)
      SetMatrix33LLine2(Inverse33, 2, 4, 3)
      SetMatrix33LLine3(Inverse33, 19, 37, 26)
      MatrixSize = 3
      
    Case 2
      SetMatrix33LLine1(Inverse33, -30, -39, -22)
      SetMatrix33LLine2(Inverse33, 23, 30, 17)
      SetMatrix33LLine3(Inverse33, -19, -25, -14)
      MatrixSize = 3
      
    Case 3
      SetMatrix33LLine1(Inverse33, 1, -13, 11)
      SetMatrix33LLine2(Inverse33, 1, -18, 15)
      SetMatrix33LLine3(Inverse33, -1, 17, -14)
      MatrixSize = 3
      
    Case 4
      SetMatrix33LLine1(Inverse33, -3, -1, 2)
      SetMatrix33LLine2(Inverse33, -10, -3, 7)
      SetMatrix33LLine3(Inverse33, -42, -13, 30)
      MatrixSize = 3
      
    Case 5
      SetMatrix33LLine1(Inverse33, 3, -3, 5)
      SetMatrix33LLine2(Inverse33, -14, 13, -21)
      SetMatrix33LLine3(Inverse33, 5, -5, 8)
      MatrixSize = 3
      
    Case 6
      SetMatrix33LLine1(Inverse33, -77, -83, 25)
      SetMatrix33LLine2(Inverse33, -65, -70, 21)
      SetMatrix33LLine3(Inverse33, 40, 43, -13)
      MatrixSize = 3
      
    Case 7
      SetMatrix33LLine1(Inverse33, 35, -96, -73)
      SetMatrix33LLine2(Inverse33, -3, 8, 6)
      SetMatrix33LLine3(Inverse33, 12, -33, -25)
      MatrixSize = 3
      
    Case 8
      SetMatrix33LLine1(Inverse33, 54, 29, -63)
      SetMatrix33LLine2(Inverse33, -24, -13, 28)
      SetMatrix33LLine3(Inverse33, -13, -7, 15)
      MatrixSize = 3
      
    Case 9
      SetMatrix33LLine1(Inverse33, 5, 27, -34)
      SetMatrix33LLine2(Inverse33, 0, 1, -1)
      SetMatrix33LLine3(Inverse33, 3, 15, -19)
      MatrixSize = 3
      
    Case 10
      SetMatrix33LLine1(Inverse33, 0, 1, -1)
      SetMatrix33LLine2(Inverse33, 1, -54, 49)
      SetMatrix33LLine3(Inverse33, 0, 9, -8)
      MatrixSize = 3
      
    Case 11
      SetMatrix33LLine1(Inverse33, 3, -25, 51)
      SetMatrix33LLine2(Inverse33, 3, -26, 53)
      SetMatrix33LLine3(Inverse33, -4, 34, -69)
      MatrixSize = 3
      
    Case 12
      SetMatrix33LLine1(Inverse33, 18, -13, -2)
      SetMatrix33LLine2(Inverse33, 69, -50, -8)
      SetMatrix33LLine3(Inverse33, -113, 82, 13)
      MatrixSize = 3
      
    Case 13
      SetMatrix44LLine1(Inverse44, -37, 28, 35, 26)
      SetMatrix44LLine2(Inverse44, -54, 41, 51, 38)
      SetMatrix44LLine3(Inverse44, -379, 287, 357, 267)
      SetMatrix44LLine4(Inverse44, 115, -87, -108, -81)
      MatrixSize = 4
      
    Case 14
      SetMatrix44LLine1(Inverse44, -8, 14, 31, -31)
      SetMatrix44LLine2(Inverse44, 79, -138, -306, 304)
      SetMatrix44LLine3(Inverse44, -40, 70, 155, -154)
      SetMatrix44LLine4(Inverse44, 36, -63, -140, 139)
      MatrixSize = 4
      
    Case 15
      SetMatrix44LLine1(Inverse44, -218, 12, 7, -178)
      SetMatrix44LLine2(Inverse44, -33, 2, 1, -27)
      SetMatrix44LLine3(Inverse44, -126, 7, 4, -103)
      SetMatrix44LLine4(Inverse44, -222, 12, 7, -181)
      MatrixSize = 4
      
    Case 16
      SetMatrix44LLine1(Inverse44, -457, 590, -302, -480)
      SetMatrix44LLine2(Inverse44, 162, -209, 107, 170)
      SetMatrix44LLine3(Inverse44, 100, -129, 66, 105)
      SetMatrix44LLine4(Inverse44, 416, -537, 275, 437)
      MatrixSize = 4
      
    Case 17
      SetMatrix44LLine1(Inverse44, 389, -12, -215, -2)
      SetMatrix44LLine2(Inverse44, 199, -6, -110, -1)
      SetMatrix44LLine3(Inverse44, 2, 0, -1, 0)
      SetMatrix44LLine4(Inverse44, -548, 17, 303, 3)
      MatrixSize = 4
      
    Case 18
      SetMatrix44LLine1(Inverse44, -349, 408, 1271, -72)
      SetMatrix44LLine2(Inverse44, 53, -62, -193, 11)
      SetMatrix44LLine3(Inverse44, 184, -215, -670, 38)
      SetMatrix44LLine4(Inverse44, -267, 312, 972, -55)
      MatrixSize = 4
      
    Case 19
      SetMatrix44LLine1(Inverse44, -7, -8, 42, -60)
      SetMatrix44LLine2(Inverse44, 20, 22, -119, 171)
      SetMatrix44LLine3(Inverse44, -18, -20, 108, -155)
      SetMatrix44LLine4(Inverse44, -19, -21, 113, -162)
      MatrixSize = 4
      
    Case 20
      SetMatrix44LLine1(Inverse44, -49, 175, -42, -229)
      SetMatrix44LLine2(Inverse44, -106, 378, -91, -495)
      SetMatrix44LLine3(Inverse44, -78, 278, -67, -364)
      SetMatrix44LLine4(Inverse44, -41, 146, -35, -191)
      MatrixSize = 4
      
    Case 21
      SetMatrix44LLine1(Inverse44, 4, 22, -5, 29)
      SetMatrix44LLine2(Inverse44, -28, -167, 37, -217)
      SetMatrix44LLine3(Inverse44, -13, -77, 17, -100)
      SetMatrix44LLine4(Inverse44, -32, -190, 42, -247)
      MatrixSize = 4
      
    Case 22
      SetMatrix44LLine1(Inverse44, 10, 49, 22, 19)
      SetMatrix44LLine2(Inverse44, 0, 0, 1, -1)
      SetMatrix44LLine3(Inverse44, -1, -5, -3, -1)
      SetMatrix44LLine4(Inverse44, 4, 19, 8, 8)
      MatrixSize = 4
      
    Case 23
      SetMatrix44LLine1(Inverse44, -222, 292, -589, -33)
      SetMatrix44LLine2(Inverse44, -586, 771, -1555, -87)
      SetMatrix44LLine3(Inverse44, -317, 417, -841, -47)
      SetMatrix44LLine4(Inverse44, -323, 425, -857, -48)
      MatrixSize = 4
      
    Case 24
      SetMatrix44LLine1(Inverse44, -419, -839, 113, 367)
      SetMatrix44LLine2(Inverse44, -434, -869, 117, 380)
      SetMatrix44LLine3(Inverse44, -371, -743, 100, 325)
      SetMatrix44LLine4(Inverse44, 56, 112, -15, -49)
      MatrixSize = 4
      
    Case 25
      SetMatrix44LLine1(Inverse44, 175, -45, -125, 36)
      SetMatrix44LLine2(Inverse44, -102, 26, 73, -21)
      SetMatrix44LLine3(Inverse44, 346, -89, -247, 71)
      SetMatrix44LLine4(Inverse44, 136, -35, -97, 28)
      MatrixSize = 4
      
    Case 26
      SetMatrix44LLine1(Inverse44, 3, 25, -8, -6)
      SetMatrix44LLine2(Inverse44, 65, 527, -167, -125)
      SetMatrix44LLine3(Inverse44, 26, 211, -67, -50)
      SetMatrix44LLine4(Inverse44, 40, 325, -103, -77)
      MatrixSize = 4
      
  EndSelect 
  
  MaxChar.l = ReadLong(FileID)
  
  Select MatrixSize
      
    Case 3
      For Index = 0 To MaxChar - 1 Step 3
        
        ReadVector3L(FileID, VectorCoded3)
        ProductMatrix33LVector3L(VectorDecoded3, Inverse33, VectorCoded3)
        String.s = String + Chr(GetVector3Li(VectorDecoded3)) + Chr(GetVector3Lj(VectorDecoded3)) + Chr(GetVector3Lk(VectorDecoded3))
        
      Next
      
    Case 4
      For Index = 0 To MaxChar - 1 Step 4
        
        ReadVector4L(FileID, VectorCoded4)
        ProductMatrix44LVector4L(VectorDecoded4, Inverse44, VectorCoded4)
        String.s = String + Chr(GetVector4Li(VectorDecoded4)) + Chr(GetVector4Lj(VectorDecoded4)) + Chr(GetVector4Lk(VectorDecoded4))+ Chr(GetVector4Ll(VectorDecoded4))
        
      Next
      
  EndSelect
  
  ProcedureReturn String
EndProcedure
    
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< WriteEncodedString <<<<<
    
ProcedureDLL WriteEncodedString(FileID.l, String.s)
  
  Matrix33.Matrix33L
  VectorCoded3.Vector3L
  VectorDecoded3.Vector3L
  Matrix44.Matrix44L
  VectorCoded4.Vector4L
  VectorDecoded4.Vector4L
  
  MatrixID = Random(26)
  
  Select MatrixID
      
    Case 0
      SetMatrix33LLine1(Matrix33, -9, 0, -2)
      SetMatrix33LLine2(Matrix33, -3, -7, 0)
      SetMatrix33LLine3(Matrix33, -7, -6, -1)
      MatrixSize.b = 3
      
    Case 1
      SetMatrix33LLine1(Matrix33, 7, -1, 9)
      SetMatrix33LLine2(Matrix33, -5, -3, -6)
      SetMatrix33LLine3(Matrix33, 2, 5, 2)
      MatrixSize = 3
      
    Case 2
      SetMatrix33LLine1(Matrix33, -5, -4, 3)
      SetMatrix33LLine2(Matrix33, 1, -2, -4)
      SetMatrix33LLine3(Matrix33, 5, 9, 3)
      MatrixSize = 3
      
    Case 3 
      SetMatrix33LLine1(Matrix33, 3, -5, -3)
      SetMatrix33LLine2(Matrix33, 1, 3, 4)
      SetMatrix33LLine3(Matrix33, 1, 4, 5)
      MatrixSize = 3
      
    Case 4
      SetMatrix33LLine1(Matrix33, -1, -4, 1)
      SetMatrix33LLine2(Matrix33, -6, 6, -1)
      SetMatrix33LLine3(Matrix33, -4, -3, 1)
      MatrixSize = 3
      
    Case 5
      SetMatrix33LLine1(Matrix33, -1, -1, -2)
      SetMatrix33LLine2(Matrix33, 7, -1, -7)
      SetMatrix33LLine3(Matrix33, 5, 0, -3)
      MatrixSize = 3
      
    Case 6
      SetMatrix33LLine1(Matrix33, 7, -4, 7)
      SetMatrix33LLine2(Matrix33, -5, 1, -8)
      SetMatrix33LLine3(Matrix33, 5, -9, -5)
      MatrixSize = 3
      
    Case 7
      SetMatrix33LLine1(Matrix33, 2, -9, -8)
      SetMatrix33LLine2(Matrix33, 3, -1, -9)
      SetMatrix33LLine3(Matrix33, -3, -3, 8)
      MatrixSize = 3
      
    Case 8
      SetMatrix33LLine1(Matrix33, 1, 6, -7)
      SetMatrix33LLine2(Matrix33, -4, -9, 0)
      SetMatrix33LLine3(Matrix33, -1, 1, -6)
      MatrixSize = 3
      
    Case 9 
      SetMatrix33LLine1(Matrix33, -4, 3, 7)
      SetMatrix33LLine2(Matrix33, -3, 7, 5)
      SetMatrix33LLine3(Matrix33, -3, 6, 5)
      MatrixSize = 3
      
    Case 10
      SetMatrix33LLine1(Matrix33, 9, 1, 5)
      SetMatrix33LLine2(Matrix33, -8, 0, 1)
      SetMatrix33LLine3(Matrix33, -9, 0, 1)
      MatrixSize = 3
      
    Case 11
      SetMatrix33LLine1(Matrix33, 8, -9, -1)
      SetMatrix33LLine2(Matrix33, 5, 3, 6)
      SetMatrix33LLine3(Matrix33, 2, 2, 3)
      MatrixSize = 3
      
    Case 12 
      SetMatrix33LLine1(Matrix33, 6, 5, 4)
      SetMatrix33LLine2(Matrix33, 7, 8, 6)
      SetMatrix33LLine3(Matrix33, 8, -7, -3)
      MatrixSize = 3
      
    Case 13
      SetMatrix44LLine1(Matrix44, -9, 0, 3, 7)
      SetMatrix44LLine2(Matrix44, -6, 9, -1, -1)
      SetMatrix44LLine3(Matrix44, 2, -2, 1, 3)
      SetMatrix44LLine4(Matrix44, -9, -7, 4, 7)
      MatrixSize = 4
      
    Case 14
      SetMatrix44LLine1(Matrix44, 2, 7, 8, -6)
      SetMatrix44LLine2(Matrix44, -1, 4, 9, 1)
      SetMatrix44LLine3(Matrix44, -4, 0, -1, -2)
      SetMatrix44LLine4(Matrix44, -5, 0, 1, 0)
      MatrixSize = 4
      
    Case 15
      SetMatrix44LLine1(Matrix44, -2, -3, 6, -1)
      SetMatrix44LLine2(Matrix44, 3, 6, -5, -1)
      SetMatrix44LLine3(Matrix44, 9, -2, -8, -4)
      SetMatrix44LLine4(Matrix44, 3, 4, -8, 1)
      MatrixSize = 4
      
    Case 16
      SetMatrix44LLine1(Matrix44, 3, 6, 4, 0)
      SetMatrix44LLine2(Matrix44, 6, 1, 5, 5)
      SetMatrix44LLine3(Matrix44, 4, 4, -9, 5)
      SetMatrix44LLine4(Matrix44, 2, -7, 8, 3)
      MatrixSize = 4
      
    Case 17
      SetMatrix44LLine1(Matrix44, 1, -2, 5, 0)
      SetMatrix44LLine2(Matrix44, -5, 7, 2, -1)
      SetMatrix44LLine3(Matrix44, 2, -4, 9, 0)
      SetMatrix44LLine4(Matrix44, 9, -1, -7, 6)
      MatrixSize = 4
      
    Case 18
      SetMatrix44LLine1(Matrix44, 9, 7, 2, -9)
      SetMatrix44LLine2(Matrix44, 2, -8, 9, 2)
      SetMatrix44LLine3(Matrix44, 2, 5, -2, -3)
      SetMatrix44LLine4(Matrix44, 3, 9, 6, 2)
      MatrixSize = 4
      
    Case 19
      SetMatrix44LLine1(Matrix44, 1, 2, 6, -4)
      SetMatrix44LLine2(Matrix44, -7, 5, 3, 5)
      SetMatrix44LLine3(Matrix44, -4, 7, 3, 6)
      SetMatrix44LLine4(Matrix44, -2, 4, 1, 4)
      MatrixSize = 4
      
    Case 20
      SetMatrix44LLine1(Matrix44, 8, -1, 0, -7)
      SetMatrix44LLine2(Matrix44, 7, -8, 7, -1)
      SetMatrix44LLine3(Matrix44, -2, 6, -9, 4)
      SetMatrix44LLine4(Matrix44, 4, -7, 7, 0)
      MatrixSize = 4
      
    Case 21
      SetMatrix44LLine1(Matrix44, 2, 1, -9, 3)
      SetMatrix44LLine2(Matrix44, -1, -1, -8, 4)
      SetMatrix44LLine3(Matrix44, -3, 8, 4, -9)
      SetMatrix44LLine4(Matrix44, 0, 2, 8, -5)
      MatrixSize = 4
      
    Case 22
      SetMatrix44LLine1(Matrix44, -4, 1, -5, 9)
      SetMatrix44LLine2(Matrix44, 0, -4, -4, -1)
      SetMatrix44LLine3(Matrix44, 1, 5, 6, -1)
      SetMatrix44LLine4(Matrix44, 1, 4, 6, -1)
      MatrixSize = 4
      
    Case 23
      SetMatrix44LLine1(Matrix44, -8, 9, -9, -2)
      SetMatrix44LLine2(Matrix44, -9, -1, 0, 8)
      SetMatrix44LLine3(Matrix44, -1, -4, 3, 5)
      SetMatrix44LLine4(Matrix44, -8, 2, 7, -5)
      MatrixSize = 4
      
    Case 24
      SetMatrix44LLine1(Matrix44, -6, -1, 9, 7)
      SetMatrix44LLine2(Matrix44, 7, -3, -5, -4)
      SetMatrix44LLine3(Matrix44, 7, 0, -7, 6)
      SetMatrix44LLine4(Matrix44, 7, -8, 1, -3)
      MatrixSize = 4
      
    Case 25
      SetMatrix44LLine1(Matrix44, -9, -2, 2, 5)
      SetMatrix44LLine2(Matrix44, -8, -5, 1, 4)
      SetMatrix44LLine3(Matrix44, -8, -1, 1, 7)
      SetMatrix44LLine4(Matrix44, 6, 0, -5, 5)
      MatrixSize = 4
      
    Case 26
      SetMatrix44LLine1(Matrix44, -6, 3, 4, -7)
      SetMatrix44LLine2(Matrix44, -1, -1, -2, 3)
      SetMatrix44LLine3(Matrix44, -1, 1, -7, 3)
      SetMatrix44LLine4(Matrix44, -6, -4, 3, 5)
      MatrixSize = 4
      
  EndSelect 
  
  WriteByte(FileID, MatrixID)
  MaxChar.l = Len(String)
  WriteLong(FileID, MaxChar)
  
  Select MatrixSize
      
    Case 3
      For Index = 0 To MaxChar - 1 Step 3
        
        SetVector3Li(VectorDecoded3, Asc(Mid(String, Index + 1, 1)))
        SetVector3Lj(VectorDecoded3, Asc(Mid(String, Index + 2, 1)))
        SetVector3Lk(VectorDecoded3, Asc(Mid(String, Index + 3, 1)))
        ProductMatrix33LVector3L(VectorCoded3, Matrix33, VectorDecoded3)
        WriteVector3L(FileID, VectorCoded3)
        
      Next
      
    Case 4
      For Index = 0 To MaxChar - 1 Step 4
        
        SetVector4Li(VectorDecoded4, Asc(Mid(String, Index + 1, 1)))
        SetVector4Lj(VectorDecoded4, Asc(Mid(String, Index + 2, 1)))
        SetVector4Lk(VectorDecoded4, Asc(Mid(String, Index + 3, 1)))
        SetVector4Ll(VectorDecoded4, Asc(Mid(String, Index + 4, 1)))
        
        ProductMatrix44LVector4L(VectorCoded4, Matrix44, VectorDecoded4)
        WriteVector4L(FileID, VectorCoded4)
        
      Next
      
  EndSelect
  
EndProcedure
  
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< ReadEncodedStringMemory <<<<<
  
ProcedureDLL.s ReadEncodedStringMemory(MemoryBuffer)
  
  Inverse33.Matrix33L
  VectorDecoded3.Vector3L
  Inverse44.Matrix44L
  VectorDecoded4.Vector4L
  
  MatrixID.b = PeekB(MemoryBuffer)
  
  Select MatrixID
      
    Case 0
      SetMatrix33LLine1(Inverse33, -7, -12, 14)
      SetMatrix33LLine2(Inverse33, 3, 5, -6)
      SetMatrix33LLine3(Inverse33, 31, 54, -63)
      MatrixSize.b = 3
      
    Case 1
      SetMatrix33LLine1(Inverse33, -24, -47, -33)
      SetMatrix33LLine2(Inverse33, 2, 4, 3)
      SetMatrix33LLine3(Inverse33, 19, 37, 26)
      MatrixSize = 3
      
    Case 2
      SetMatrix33LLine1(Inverse33, -30, -39, -22)
      SetMatrix33LLine2(Inverse33, 23, 30, 17)
      SetMatrix33LLine3(Inverse33, -19, -25, -14)
      MatrixSize = 3
      
    Case 3
      SetMatrix33LLine1(Inverse33, 1, -13, 11)
      SetMatrix33LLine2(Inverse33, 1, -18, 15)
      SetMatrix33LLine3(Inverse33, -1, 17, -14)
      MatrixSize = 3
      
    Case 4
      SetMatrix33LLine1(Inverse33, -3, -1, 2)
      SetMatrix33LLine2(Inverse33, -10, -3, 7)
      SetMatrix33LLine3(Inverse33, -42, -13, 30)
      MatrixSize = 3
      
    Case 5
      SetMatrix33LLine1(Inverse33, 3, -3, 5)
      SetMatrix33LLine2(Inverse33, -14, 13, -21)
      SetMatrix33LLine3(Inverse33, 5, -5, 8)
      MatrixSize = 3
      
    Case 6
      SetMatrix33LLine1(Inverse33, -77, -83, 25)
      SetMatrix33LLine2(Inverse33, -65, -70, 21)
      SetMatrix33LLine3(Inverse33, 40, 43, -13)
      MatrixSize = 3
      
    Case 7
      SetMatrix33LLine1(Inverse33, 35, -96, -73)
      SetMatrix33LLine2(Inverse33, -3, 8, 6)
      SetMatrix33LLine3(Inverse33, 12, -33, -25)
      MatrixSize = 3
      
    Case 8
      SetMatrix33LLine1(Inverse33, 54, 29, -63)
      SetMatrix33LLine2(Inverse33, -24, -13, 28)
      SetMatrix33LLine3(Inverse33, -13, -7, 15)
      MatrixSize = 3
      
    Case 9
      SetMatrix33LLine1(Inverse33, 5, 27, -34)
      SetMatrix33LLine2(Inverse33, 0, 1, -1)
      SetMatrix33LLine3(Inverse33, 3, 15, -19)
      MatrixSize = 3
      
    Case 10
      SetMatrix33LLine1(Inverse33, 0, 1, -1)
      SetMatrix33LLine2(Inverse33, 1, -54, 49)
      SetMatrix33LLine3(Inverse33, 0, 9, -8)
      MatrixSize = 3
      
    Case 11
      SetMatrix33LLine1(Inverse33, 3, -25, 51)
      SetMatrix33LLine2(Inverse33, 3, -26, 53)
      SetMatrix33LLine3(Inverse33, -4, 34, -69)
      MatrixSize = 3
      
    Case 12
      SetMatrix33LLine1(Inverse33, 18, -13, -2)
      SetMatrix33LLine2(Inverse33, 69, -50, -8)
      SetMatrix33LLine3(Inverse33, -113, 82, 13)
      MatrixSize = 3
      
    Case 13
      SetMatrix44LLine1(Inverse44, -37, 28, 35, 26)
      SetMatrix44LLine2(Inverse44, -54, 41, 51, 38)
      SetMatrix44LLine3(Inverse44, -379, 287, 357, 267)
      SetMatrix44LLine4(Inverse44, 115, -87, -108, -81)
      MatrixSize = 4
      
    Case 14
      SetMatrix44LLine1(Inverse44, -8, 14, 31, -31)
      SetMatrix44LLine2(Inverse44, 79, -138, -306, 304)
      SetMatrix44LLine3(Inverse44, -40, 70, 155, -154)
      SetMatrix44LLine4(Inverse44, 36, -63, -140, 139)
      MatrixSize = 4
      
    Case 15
      SetMatrix44LLine1(Inverse44, -218, 12, 7, -178)
      SetMatrix44LLine2(Inverse44, -33, 2, 1, -27)
      SetMatrix44LLine3(Inverse44, -126, 7, 4, -103)
      SetMatrix44LLine4(Inverse44, -222, 12, 7, -181)
      MatrixSize = 4
      
    Case 16
      SetMatrix44LLine1(Inverse44, -457, 590, -302, -480)
      SetMatrix44LLine2(Inverse44, 162, -209, 107, 170)
      SetMatrix44LLine3(Inverse44, 100, -129, 66, 105)
      SetMatrix44LLine4(Inverse44, 416, -537, 275, 437)
      MatrixSize = 4
      
    Case 17
      SetMatrix44LLine1(Inverse44, 389, -12, -215, -2)
      SetMatrix44LLine2(Inverse44, 199, -6, -110, -1)
      SetMatrix44LLine3(Inverse44, 2, 0, -1, 0)
      SetMatrix44LLine4(Inverse44, -548, 17, 303, 3)
      MatrixSize = 4
      
    Case 18
      SetMatrix44LLine1(Inverse44, -349, 408, 1271, -72)
      SetMatrix44LLine2(Inverse44, 53, -62, -193, 11)
      SetMatrix44LLine3(Inverse44, 184, -215, -670, 38)
      SetMatrix44LLine4(Inverse44, -267, 312, 972, -55)
      MatrixSize = 4
      
    Case 19
      SetMatrix44LLine1(Inverse44, -7, -8, 42, -60)
      SetMatrix44LLine2(Inverse44, 20, 22, -119, 171)
      SetMatrix44LLine3(Inverse44, -18, -20, 108, -155)
      SetMatrix44LLine4(Inverse44, -19, -21, 113, -162)
      MatrixSize = 4
      
    Case 20
      SetMatrix44LLine1(Inverse44, -49, 175, -42, -229)
      SetMatrix44LLine2(Inverse44, -106, 378, -91, -495)
      SetMatrix44LLine3(Inverse44, -78, 278, -67, -364)
      SetMatrix44LLine4(Inverse44, -41, 146, -35, -191)
      MatrixSize = 4
      
    Case 21
      SetMatrix44LLine1(Inverse44, 4, 22, -5, 29)
      SetMatrix44LLine2(Inverse44, -28, -167, 37, -217)
      SetMatrix44LLine3(Inverse44, -13, -77, 17, -100)
      SetMatrix44LLine4(Inverse44, -32, -190, 42, -247)
      MatrixSize = 4
      
    Case 22
      SetMatrix44LLine1(Inverse44, 10, 49, 22, 19)
      SetMatrix44LLine2(Inverse44, 0, 0, 1, -1)
      SetMatrix44LLine3(Inverse44, -1, -5, -3, -1)
      SetMatrix44LLine4(Inverse44, 4, 19, 8, 8)
      MatrixSize = 4
      
    Case 23
      SetMatrix44LLine1(Inverse44, -222, 292, -589, -33)
      SetMatrix44LLine2(Inverse44, -586, 771, -1555, -87)
      SetMatrix44LLine3(Inverse44, -317, 417, -841, -47)
      SetMatrix44LLine4(Inverse44, -323, 425, -857, -48)
      MatrixSize = 4
      
    Case 24
      SetMatrix44LLine1(Inverse44, -419, -839, 113, 367)
      SetMatrix44LLine2(Inverse44, -434, -869, 117, 380)
      SetMatrix44LLine3(Inverse44, -371, -743, 100, 325)
      SetMatrix44LLine4(Inverse44, 56, 112, -15, -49)
      MatrixSize = 4
      
    Case 25
      SetMatrix44LLine1(Inverse44, 175, -45, -125, 36)
      SetMatrix44LLine2(Inverse44, -102, 26, 73, -21)
      SetMatrix44LLine3(Inverse44, 346, -89, -247, 71)
      SetMatrix44LLine4(Inverse44, 136, -35, -97, 28)
      MatrixSize = 4
      
    Case 26
      SetMatrix44LLine1(Inverse44, 3, 25, -8, -6)
      SetMatrix44LLine2(Inverse44, 65, 527, -167, -125)
      SetMatrix44LLine3(Inverse44, 26, 211, -67, -50)
      SetMatrix44LLine4(Inverse44, 40, 325, -103, -77)
      MatrixSize = 4
      
  EndSelect 
  
  MaxChar.l = PeekL(MemoryBuffer + SizeOf(Byte))
  
  Select MatrixSize
      
    Case 3
      
      *VectorCoded3.Vector3L = MemoryBuffer + SizeOf(Byte) + SizeOf(Long)
      
      For Index = 0 To MaxChar - 1 Step 3
        
        ProductMatrix33LVector3L(VectorDecoded3, Inverse33, *VectorCoded3)
        String.s = String + Chr(GetVector3Li(VectorDecoded3)) + Chr(GetVector3Lj(VectorDecoded3)) + Chr(GetVector3Lk(VectorDecoded3))
        *VectorCoded3 + SizeOf(Vector3L)
        
      Next
      
    Case 4
      
      *VectorCoded4.Vector4L = MemoryBuffer + SizeOf(Byte) + SizeOf(Long)
      
      For Index = 0 To MaxChar - 1 Step 4
        
        ProductMatrix44LVector4L(VectorDecoded4, Inverse44, *VectorCoded4)
        String.s = String + Chr(GetVector4Li(VectorDecoded4)) + Chr(GetVector4Lj(VectorDecoded4)) + Chr(GetVector4Lk(VectorDecoded4))+ Chr(GetVector4Ll(VectorDecoded4))
        *VectorCoded4 + SizeOf(Vector4L)
        
      Next
      
  EndSelect
  
  ProcedureReturn String
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< WriteEncodedStringMemory <<<<<

ProcedureDLL WriteEncodedStringMemory(String.s)
  
  Matrix33.Matrix33L
  VectorDecoded3.Vector3L
  Matrix44.Matrix44L
  VectorDecoded4.Vector4L
  
  MatrixID = Random(26)
  
  Select MatrixID
      
    Case 0
      SetMatrix33LLine1(Matrix33, -9, 0, -2)
      SetMatrix33LLine2(Matrix33, -3, -7, 0)
      SetMatrix33LLine3(Matrix33, -7, -6, -1)
      MatrixSize.b = 3
      
    Case 1
      SetMatrix33LLine1(Matrix33, 7, -1, 9)
      SetMatrix33LLine2(Matrix33, -5, -3, -6)
      SetMatrix33LLine3(Matrix33, 2, 5, 2)
      MatrixSize = 3
      
    Case 2
      SetMatrix33LLine1(Matrix33, -5, -4, 3)
      SetMatrix33LLine2(Matrix33, 1, -2, -4)
      SetMatrix33LLine3(Matrix33, 5, 9, 3)
      MatrixSize = 3
      
    Case 3 
      SetMatrix33LLine1(Matrix33, 3, -5, -3)
      SetMatrix33LLine2(Matrix33, 1, 3, 4)
      SetMatrix33LLine3(Matrix33, 1, 4, 5)
      MatrixSize = 3
      
    Case 4
      SetMatrix33LLine1(Matrix33, -1, -4, 1)
      SetMatrix33LLine2(Matrix33, -6, 6, -1)
      SetMatrix33LLine3(Matrix33, -4, -3, 1)
      MatrixSize = 3
      
    Case 5
      SetMatrix33LLine1(Matrix33, -1, -1, -2)
      SetMatrix33LLine2(Matrix33, 7, -1, -7)
      SetMatrix33LLine3(Matrix33, 5, 0, -3)
      MatrixSize = 3
      
    Case 6
      SetMatrix33LLine1(Matrix33, 7, -4, 7)
      SetMatrix33LLine2(Matrix33, -5, 1, -8)
      SetMatrix33LLine3(Matrix33, 5, -9, -5)
      MatrixSize = 3
      
    Case 7
      SetMatrix33LLine1(Matrix33, 2, -9, -8)
      SetMatrix33LLine2(Matrix33, 3, -1, -9)
      SetMatrix33LLine3(Matrix33, -3, -3, 8)
      MatrixSize = 3
      
    Case 8
      SetMatrix33LLine1(Matrix33, 1, 6, -7)
      SetMatrix33LLine2(Matrix33, -4, -9, 0)
      SetMatrix33LLine3(Matrix33, -1, 1, -6)
      MatrixSize = 3
      
    Case 9 
      SetMatrix33LLine1(Matrix33, -4, 3, 7)
      SetMatrix33LLine2(Matrix33, -3, 7, 5)
      SetMatrix33LLine3(Matrix33, -3, 6, 5)
      MatrixSize = 3
      
    Case 10
      SetMatrix33LLine1(Matrix33, 9, 1, 5)
      SetMatrix33LLine2(Matrix33, -8, 0, 1)
      SetMatrix33LLine3(Matrix33, -9, 0, 1)
      MatrixSize = 3
      
    Case 11
      SetMatrix33LLine1(Matrix33, 8, -9, -1)
      SetMatrix33LLine2(Matrix33, 5, 3, 6)
      SetMatrix33LLine3(Matrix33, 2, 2, 3)
      MatrixSize = 3
      
    Case 12 
      SetMatrix33LLine1(Matrix33, 6, 5, 4)
      SetMatrix33LLine2(Matrix33, 7, 8, 6)
      SetMatrix33LLine3(Matrix33, 8, -7, -3)
      MatrixSize = 3
      
    Case 13
      SetMatrix44LLine1(Matrix44, -9, 0, 3, 7)
      SetMatrix44LLine2(Matrix44, -6, 9, -1, -1)
      SetMatrix44LLine3(Matrix44, 2, -2, 1, 3)
      SetMatrix44LLine4(Matrix44, -9, -7, 4, 7)
      MatrixSize = 4
      
    Case 14
      SetMatrix44LLine1(Matrix44, 2, 7, 8, -6)
      SetMatrix44LLine2(Matrix44, -1, 4, 9, 1)
      SetMatrix44LLine3(Matrix44, -4, 0, -1, -2)
      SetMatrix44LLine4(Matrix44, -5, 0, 1, 0)
      MatrixSize = 4
      
    Case 15
      SetMatrix44LLine1(Matrix44, -2, -3, 6, -1)
      SetMatrix44LLine2(Matrix44, 3, 6, -5, -1)
      SetMatrix44LLine3(Matrix44, 9, -2, -8, -4)
      SetMatrix44LLine4(Matrix44, 3, 4, -8, 1)
      MatrixSize = 4
      
    Case 16
      SetMatrix44LLine1(Matrix44, 3, 6, 4, 0)
      SetMatrix44LLine2(Matrix44, 6, 1, 5, 5)
      SetMatrix44LLine3(Matrix44, 4, 4, -9, 5)
      SetMatrix44LLine4(Matrix44, 2, -7, 8, 3)
      MatrixSize = 4
      
    Case 17
      SetMatrix44LLine1(Matrix44, 1, -2, 5, 0)
      SetMatrix44LLine2(Matrix44, -5, 7, 2, -1)
      SetMatrix44LLine3(Matrix44, 2, -4, 9, 0)
      SetMatrix44LLine4(Matrix44, 9, -1, -7, 6)
      MatrixSize = 4
      
    Case 18
      SetMatrix44LLine1(Matrix44, 9, 7, 2, -9)
      SetMatrix44LLine2(Matrix44, 2, -8, 9, 2)
      SetMatrix44LLine3(Matrix44, 2, 5, -2, -3)
      SetMatrix44LLine4(Matrix44, 3, 9, 6, 2)
      MatrixSize = 4
      
    Case 19
      SetMatrix44LLine1(Matrix44, 1, 2, 6, -4)
      SetMatrix44LLine2(Matrix44, -7, 5, 3, 5)
      SetMatrix44LLine3(Matrix44, -4, 7, 3, 6)
      SetMatrix44LLine4(Matrix44, -2, 4, 1, 4)
      MatrixSize = 4
      
    Case 20
      SetMatrix44LLine1(Matrix44, 8, -1, 0, -7)
      SetMatrix44LLine2(Matrix44, 7, -8, 7, -1)
      SetMatrix44LLine3(Matrix44, -2, 6, -9, 4)
      SetMatrix44LLine4(Matrix44, 4, -7, 7, 0)
      MatrixSize = 4
      
    Case 21
      SetMatrix44LLine1(Matrix44, 2, 1, -9, 3)
      SetMatrix44LLine2(Matrix44, -1, -1, -8, 4)
      SetMatrix44LLine3(Matrix44, -3, 8, 4, -9)
      SetMatrix44LLine4(Matrix44, 0, 2, 8, -5)
      MatrixSize = 4
      
    Case 22
      SetMatrix44LLine1(Matrix44, -4, 1, -5, 9)
      SetMatrix44LLine2(Matrix44, 0, -4, -4, -1)
      SetMatrix44LLine3(Matrix44, 1, 5, 6, -1)
      SetMatrix44LLine4(Matrix44, 1, 4, 6, -1)
      MatrixSize = 4
      
    Case 23
      SetMatrix44LLine1(Matrix44, -8, 9, -9, -2)
      SetMatrix44LLine2(Matrix44, -9, -1, 0, 8)
      SetMatrix44LLine3(Matrix44, -1, -4, 3, 5)
      SetMatrix44LLine4(Matrix44, -8, 2, 7, -5)
      MatrixSize = 4
      
    Case 24
      SetMatrix44LLine1(Matrix44, -6, -1, 9, 7)
      SetMatrix44LLine2(Matrix44, 7, -3, -5, -4)
      SetMatrix44LLine3(Matrix44, 7, 0, -7, 6)
      SetMatrix44LLine4(Matrix44, 7, -8, 1, -3)
      MatrixSize = 4
      
    Case 25
      SetMatrix44LLine1(Matrix44, -9, -2, 2, 5)
      SetMatrix44LLine2(Matrix44, -8, -5, 1, 4)
      SetMatrix44LLine3(Matrix44, -8, -1, 1, 7)
      SetMatrix44LLine4(Matrix44, 6, 0, -5, 5)
      MatrixSize = 4
      
    Case 26
      SetMatrix44LLine1(Matrix44, -6, 3, 4, -7)
      SetMatrix44LLine2(Matrix44, -1, -1, -2, 3)
      SetMatrix44LLine3(Matrix44, -1, 1, -7, 3)
      SetMatrix44LLine4(Matrix44, -6, -4, 3, 5)
      MatrixSize = 4
      
  EndSelect 
  
  MaxChar.l = Len(String)
  Len = MaxChar
  Reste = Len % MatrixSize
  
  While Reste 
    
    Len = Len + 1
    Reste = Len % MatrixSize
    
  Wend
  
  MemoryBuffer = AllocateMemory(SizeOf(Byte) + SizeOf(Long) + Len * SizeOf(Long))
  PokeB(MemoryBuffer, MatrixID)
  PokeL(MemoryBuffer + SizeOf(Byte), MaxChar)
  
  Select MatrixSize
      
    Case 3
      
      *VectorCoded3.Vector3L = MemoryBuffer + SizeOf(Byte) + SizeOf(Long)
      
      For Index = 0 To MaxChar - 1 Step 3
        
        SetVector3Li(VectorDecoded3, Asc(Mid(String, Index + 1, 1)))
        SetVector3Lj(VectorDecoded3, Asc(Mid(String, Index + 2, 1)))
        SetVector3Lk(VectorDecoded3, Asc(Mid(String, Index + 3, 1)))
        ProductMatrix33LVector3L(*VectorCoded3, Matrix33, VectorDecoded3)
        *VectorCoded3 + SizeOf(Vector3L)
        
      Next
      
    Case 4
      
      *VectorCoded4.Vector4L = MemoryBuffer + SizeOf(Byte) + SizeOf(Long)
      
      For Index = 0 To MaxChar - 1 Step 4
        
        SetVector4Li(VectorDecoded4, Asc(Mid(String, Index + 1, 1)))
        SetVector4Lj(VectorDecoded4, Asc(Mid(String, Index + 2, 1)))
        SetVector4Lk(VectorDecoded4, Asc(Mid(String, Index + 3, 1)))
        SetVector4Ll(VectorDecoded4, Asc(Mid(String, Index + 4, 1)))
        
        ProductMatrix44LVector4L(*VectorCoded4, Matrix44, VectorDecoded4)
        *VectorCoded4 + SizeOf(Vector4L)
        
      Next
      
  EndSelect
  
  ProcedureReturn MemoryBuffer
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF ENCODED STRING FUNCTION <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#BINARY_STRING_OFFSET = 999999

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< WriteBinaryString <<<<<
    
ProcedureDLL WriteBinaryString(FileID.l, String.s)
  
  MaxChar.l = Len(String)
  WriteLong(FileID, MaxChar)
  
  For Index = 0 To MaxChar - 1
    WriteLong(FileID, #BINARY_STRING_OFFSET + Asc(Mid(String, Index + 1, 1)))
  Next
  
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< ReadBinaryString <<<<<

ProcedureDLL.s ReadBinaryString(FileID.l)
  
  MaxChar.l = ReadLong(FileID)
  
  For Index = 0 To MaxChar - 1
    String.s = String + Chr(ReadLong(FileID) - #BINARY_STRING_OFFSET)
  Next
  
  ProcedureReturn String
EndProcedure
    
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< WriteBinaryStringMemory <<<<<

ProcedureDLL.i WriteBinaryStringMemory(String.s)
  
  MaxChar.l = Len(String)
  MemoryBuffer.i = AllocateMemory(SizeOf(Long) + MaxChar * SizeOf(Long))
  CurrentBuffer.i = MemoryBuffer
  PokeL(CurrentBuffer, MaxChar)
  CurrentBuffer + SizeOf(Long)
  
  For Index = 0 To MaxChar - 1
    PokeL(CurrentBuffer, #BINARY_STRING_OFFSET + Asc(Mid(String, Index + 1, 1)))
    CurrentBuffer + SizeOf(Long)
  Next
  
  ProcedureReturn MemoryBuffer
EndProcedure

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< ReadBinaryStringMemory <<<<<
  
ProcedureDLL.s ReadBinaryStringMemory(MemoryBuffer.i)
  
  CurrentBuffer.i = MemoryBuffer
  MaxChar.l = PeekL(CurrentBuffer)
  CurrentBuffer + SizeOf(Long)
  
  For Index = 0 To MaxChar - 1
    String.s = String + Chr(PeekL(CurrentBuffer) - #BINARY_STRING_OFFSET)
    CurrentBuffer + SizeOf(Long)
  Next
  
  ProcedureReturn String
EndProcedure


; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
The testing code :

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Test Read/Write Binary/Encoded String
; File : Test_Read_Write_Binary_Encoded_String.pb
; File Version : 2.0.0
; Programmation : To verify
; Programmed by : Guimauve
; Date : 30-05-2009
; Last Update : 30-05-2009
; Coded for PureBasic V4.30
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;/ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;/ <<<<< !!! WARNING - YOU ARE NOW IN A TESTING ZONE - WARNING !!! <<<<<
;/ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Dim Text.s(10)

Text(0) = "Hello world"
Text(1) = "How are you ?"
Text(2) = "I'm fine, and you ?"
Text(3) = "I'm fine too !"
Text(4) = "PureBasic 4.40 will be out soon !"
Text(5) = "PureBasic it's the best of the best."
Text(6) = "I have a machine capable to fly at 99X10^6 km/s."
Text(7) = "99X10^6 km/s is approximately 330 times the speed of light !"
Text(8) = "Indeed, it's very fast. You must know where you want to go"
Text(9) = "otherwise you will smash your face on the windshield anytime soon !"
Text(10) = "Secrets of antigravity propulsion by Paul A. LaViolette, Ph.D."

Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; <<<<< The original string <<<<<"
Debug ""

For Index = 0 To 10
  Debug Text(Index)
Next

Debug ""
Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; <<<<< EncodedString Test <<<<<"
Debug ""

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

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

Debug ""
Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; <<<<< BinaryString Test <<<<<"
Debug ""

If CreateFile(2, "BinaryStringTest.dat")
  
  For Index = 0 To 10
    WriteBinaryString(2, Text(Index))
  Next
  
  CloseFile(2)
  
EndIf

If ReadFile(3, "BinaryStringTest.dat")
  
  For Index = 0 To 10
    Debug ReadBinaryString(3)
  Next
  
  CloseFile(3)
  
EndIf

Debug ""
Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; <<<<< EncodedStringMemory Test <<<<<"
Debug ""

For Index = 0 To 10
  
  EncodedString.i = WriteEncodedStringMemory(Text(Index))
  Debug ReadEncodedStringMemory(EncodedString)
  
  If EncodedString
    FreeMemory(EncodedString)
  EndIf
  
Next
  
Debug ""
Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; <<<<< BinaryStringMemory Test <<<<<"
Debug ""

For Index = 0 To 10
  
  BinaryString.i = WriteBinaryStringMemory(Text(Index))
  Debug ReadBinaryStringMemory(BinaryString)
  
  If BinaryString
    FreeMemory(BinaryString)
  EndIf
  
Next

Debug ""
Debug "; <<<<<<<<<<<<<<<<<<<<<<<"
Debug "; <<<<< END OF TEST <<<<<"
Debug "; <<<<<<<<<<<<<<<<<<<<<<<"

; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<