Page 1 of 1

PukallCipher - Update V1.1.0

Posted: Fri Jun 12, 2009 2:05 am
by Guimauve
Hello everyone,

This is my vision of the PukallCipher algorithm. Sorry for the French comment.

Best regards.

Guimauve

Code: Select all

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Pukall Cipher algorithm
; File : PukallCiper.pb
; File Version : 1.1.0
; Programmation : OK
; Programmed by : Guimauve
; Date : 13-06-2009
; Last Update : 30-08-2009
; Coded for PureBasic V4.40 BETA 2
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Constantes Niveau Sécurité <<<<<

#PUKALLCIPHER_LEVEL_GOOD = 128
#PUKALLCIPHER_LEVEL_HIGH = 256
#PUKALLCIPHER_LEVEL_EXTREME = 512
#PUKALLCIPHER_LEVEL_INFERNAL = 1024
#PUKALLCIPHER_LEVEL_INSANE = 2048
#PUKALLCIPHER_LEVEL_RIDICULOUS = 4096
#PUKALLCIPHER_LEVEL_LUDICROUS = 8192

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Constantes de dimensionnement <<<<<

#PUKALLCIPHER_X1A0_MAX = 512
#PUKALLCIPHER_CLE_MAX = 1024

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

Structure PukallCipher
  
  Level.w
  Ax.l
  Bx.l
  cx.l
  dx.l
  Si.l
  X1A2.l
  Res.l
  Counter.l
  Inter.l
  X1A0.l[#PUKALLCIPHER_X1A0_MAX]
  Cle.c[#PUKALLCIPHER_CLE_MAX]
  X1A0Max.l
  CleMax.l
  BufferLength.l
  Char.c
  Rep.c
  Dxx.c
  Exx.c
  Cfc.l
  Cfd.l
  
EndStructure

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

Macro GetPukallCipherLevel(PukallCipherA)
  
  PukallCipherA\Level
  
EndMacro

Macro GetPukallCipherAx(PukallCipherA)
  
  PukallCipherA\Ax
  
EndMacro

Macro GetPukallCipherBx(PukallCipherA)
  
  PukallCipherA\Bx
  
EndMacro

Macro GetPukallCipherCx(PukallCipherA)
  
  PukallCipherA\cx
  
EndMacro

Macro GetPukallCipherDx(PukallCipherA)
  
  PukallCipherA\dx
  
EndMacro

Macro GetPukallCipherSi(PukallCipherA)
  
  PukallCipherA\Si
  
EndMacro

Macro GetPukallCipherX1A2(PukallCipherA)
  
  PukallCipherA\X1A2
  
EndMacro

Macro GetPukallCipherRes(PukallCipherA)
  
  PukallCipherA\Res
  
EndMacro

Macro GetPukallCipherCounter(PukallCipherA)
  
  PukallCipherA\Counter
  
EndMacro

Macro GetPukallCipherInter(PukallCipherA)
  
  PukallCipherA\Inter
  
EndMacro

Macro GetPukallCipherX1A0(PukallCipherA, Index)
  
  PukallCipherA\X1A0[Index]
  
EndMacro

Macro GetPukallCipherCle(PukallCipherA, Index)
  
  PukallCipherA\Cle[Index]
  
EndMacro

Macro GetPukallCipherX1A0Max(PukallCipherA)
  
  PukallCipherA\X1A0Max
  
EndMacro

Macro GetPukallCipherCleMax(PukallCipherA)
  
  PukallCipherA\CleMax
  
EndMacro

Macro GetPukallCipherBufferLength(PukallCipherA)
  
  PukallCipherA\BufferLength
  
EndMacro

Macro GetPukallCipherChar(PukallCipherA)
  
  PukallCipherA\Char
  
EndMacro

Macro GetPukallCipherRep(PukallCipherA)
  
  PukallCipherA\Rep
  
EndMacro

Macro GetPukallCipherDxx(PukallCipherA)
  
  PukallCipherA\Dxx
  
EndMacro

Macro GetPukallCipherExx(PukallCipherA)
  
  PukallCipherA\Exx
  
EndMacro

Macro GetPukallCipherCfc(PukallCipherA)
  
  PukallCipherA\Cfc
  
EndMacro

Macro GetPukallCipherCfd(PukallCipherA)
  
  PukallCipherA\Cfd
  
EndMacro

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

Macro SetPukallCipherLevel(PukallCipherA, P_Level)
  
  GetPukallCipherLevel(PukallCipherA) = P_Level
  
EndMacro

Macro SetPukallCipherAx(PukallCipherA, P_Ax)
  
  GetPukallCipherAx(PukallCipherA) = P_Ax
  
EndMacro

Macro SetPukallCipherBx(PukallCipherA, P_Bx)
  
  GetPukallCipherBx(PukallCipherA) = P_Bx
  
EndMacro

Macro SetPukallCipherCx(PukallCipherA, P_Cx)
  
  GetPukallCipherCx(PukallCipherA) = P_Cx
  
EndMacro

Macro SetPukallCipherDx(PukallCipherA, P_Dx)
  
  GetPukallCipherDx(PukallCipherA) = P_Dx
  
EndMacro

Macro SetPukallCipherSi(PukallCipherA, P_Si)
  
  GetPukallCipherSi(PukallCipherA) = P_Si
  
EndMacro

Macro SetPukallCipherX1A2(PukallCipherA, P_X1A2)
  
  GetPukallCipherX1A2(PukallCipherA) = P_X1A2
  
EndMacro

Macro SetPukallCipherRes(PukallCipherA, P_Res)
  
  GetPukallCipherRes(PukallCipherA) = P_Res
  
EndMacro

Macro SetPukallCipherCounter(PukallCipherA, P_Counter)
  
  GetPukallCipherCounter(PukallCipherA) = P_Counter
  
EndMacro

Macro SetPukallCipherInter(PukallCipherA, P_Inter)
  
  GetPukallCipherInter(PukallCipherA) = P_Inter
  
EndMacro

Macro SetPukallCipherX1A0(PukallCipherA, Index, P_X1A0)
  
  GetPukallCipherX1A0(PukallCipherA, Index) = P_X1A0
  
EndMacro

Macro SetPukallCipherCle(PukallCipherA, Index, P_Cle)
  
  GetPukallCipherCle(PukallCipherA, Index) = P_Cle
  
EndMacro

Macro SetPukallCipherX1A0Max(PukallCipherA, P_X1A0Max)
  
  GetPukallCipherX1A0Max(PukallCipherA) = P_X1A0Max
  
EndMacro

Macro SetPukallCipherCleMax(PukallCipherA, P_CleMax)
  
  GetPukallCipherCleMax(PukallCipherA) = P_CleMax
  
EndMacro

Macro SetPukallCipherBufferLength(PukallCipherA, P_BufferLength)
  
  GetPukallCipherBufferLength(PukallCipherA) = P_BufferLength
  
EndMacro

Macro SetPukallCipherChar(PukallCipherA, P_Char)
  
  GetPukallCipherChar(PukallCipherA) = P_Char
  
EndMacro

Macro SetPukallCipherRep(PukallCipherA, P_Rep)
  
  GetPukallCipherRep(PukallCipherA) = P_Rep
  
EndMacro

Macro SetPukallCipherDxx(PukallCipherA, P_Dxx)
  
  GetPukallCipherDxx(PukallCipherA) = P_Dxx
  
EndMacro

Macro SetPukallCipherExx(PukallCipherA, P_Exx)
  
  GetPukallCipherExx(PukallCipherA) = P_Exx
  
EndMacro

Macro SetPukallCipherCfc(PukallCipherA, P_Cfc)
  
  GetPukallCipherCfc(PukallCipherA) = P_Cfc
  
EndMacro

Macro SetPukallCipherCfd(PukallCipherA, P_Cfd)
  
  GetPukallCipherCfd(PukallCipherA) = P_Cfd
  
EndMacro

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

Macro ResetPukallCipher(PukallCipherA)
  
  SetPukallCipherLevel(PukallCipherA, 0)
  SetPukallCipherAx(PukallCipherA, 0)
  SetPukallCipherBx(PukallCipherA, 0)
  SetPukallCipherCx(PukallCipherA, 0)
  SetPukallCipherDx(PukallCipherA, 0)
  SetPukallCipherSi(PukallCipherA, 0)
  SetPukallCipherX1A2(PukallCipherA, 0)
  SetPukallCipherRes(PukallCipherA, 0)
  SetPukallCipherCounter(PukallCipherA, 0)
  SetPukallCipherInter(PukallCipherA, 0)
  
  For Index = 0 To #PUKALLCIPHER_X1A0_MAX - 1
    SetPukallCipherX1A0(PukallCipherA, Index, 0)
  Next
  
  For Index = 0 To #PUKALLCIPHER_CLE_MAX - 1
    SetPukallCipherCle(PukallCipherA, Index, 0)
  Next
  
  SetPukallCipherX1A0Max(PukallCipherA, 0)
  SetPukallCipherCleMax(PukallCipherA, 0)
  SetPukallCipherBufferLength(PukallCipherA, 0)
  SetPukallCipherChar(PukallCipherA, 0)
  SetPukallCipherRep(PukallCipherA, 0)
  SetPukallCipherDxx(PukallCipherA, 0)
  SetPukallCipherExx(PukallCipherA, 0)
  SetPukallCipherCfc(PukallCipherA, 0)
  SetPukallCipherCfd(PukallCipherA, 0)
  
EndMacro

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Code généré en : 00.094 secondes (3680.85 lignes/seconde) <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Macro Private_PukallCipherCode(PukallCipherA)
  
  SetPukallCipherDx(PukallCipherA, GetPukallCipherX1A2(PukallCipherA) + GetPukallCipherCounter(PukallCipherA))
  SetPukallCipherAx(PukallCipherA, GetPukallCipherX1A0(PukallCipherA, GetPukallCipherCounter(PukallCipherA)))
  
  SetPukallCipherBx(PukallCipherA, $015A)
  SetPukallCipherCx(PukallCipherA, $4E35)
  
  Swap GetPukallCipherAx(PukallCipherA), GetPukallCipherSi(PukallCipherA)
  Swap GetPukallCipherAx(PukallCipherA), GetPukallCipherDx(PukallCipherA)
  
  If GetPukallCipherAx(PukallCipherA) <> 0
    SetPukallCipherAx(PukallCipherA, GetPukallCipherAx(PukallCipherA) * GetPukallCipherBx(PukallCipherA))
  EndIf
  
  Swap GetPukallCipherAx(PukallCipherA), GetPukallCipherCx(PukallCipherA)
  
  If GetPukallCipherAx(PukallCipherA) <> 0
    SetPukallCipherAx(PukallCipherA, GetPukallCipherAx(PukallCipherA) * GetPukallCipherSi(PukallCipherA))
    SetPukallCipherAx(PukallCipherA, GetPukallCipherAx(PukallCipherA) + GetPukallCipherCx(PukallCipherA))
  EndIf
  
  Swap GetPukallCipherAx(PukallCipherA), GetPukallCipherSi(PukallCipherA)
  
  SetPukallCipherAx(PukallCipherA, GetPukallCipherAx(PukallCipherA) * GetPukallCipherBx(PukallCipherA))
  SetPukallCipherDx(PukallCipherA, GetPukallCipherCx(PukallCipherA) + GetPukallCipherDx(PukallCipherA))
  
  SetPukallCipherAx(PukallCipherA, GetPukallCipherAx(PukallCipherA) + 1)
  SetPukallCipherX1A2(PukallCipherA, GetPukallCipherDx(PukallCipherA))
  SetPukallCipherX1A0(PukallCipherA, GetPukallCipherCounter(PukallCipherA), GetPukallCipherAx(PukallCipherA))
  SetPukallCipherCounter(PukallCipherA, GetPukallCipherCounter(PukallCipherA) + 1)
  
  SetPukallCipherRes(PukallCipherA, GetPukallCipherAx(PukallCipherA) ! GetPukallCipherDx(PukallCipherA))
  
EndMacro

Macro Private_PukallCipherAssemble(PukallCipherA)
  
  SetPukallCipherX1A0(PukallCipherA, 0, GetPukallCipherCle(PukallCipherA, 0) * GetPukallCipherLevel(PukallCipherA) + GetPukallCipherCle(PukallCipherA, 1))
  Private_PukallCipherCode(PukallCipherA)
  SetPukallCipherInter(PukallCipherA, GetPukallCipherRes(PukallCipherA))
  
  KeyIndex = 2
  
  For Index = 1 To GetPukallCipherX1A0Max(PukallCipherA) - 1
    
    SetPukallCipherX1A0(PukallCipherA, Index, GetPukallCipherX1A0(PukallCipherA, Index - 1) ! GetPukallCipherCle(PukallCipherA, KeyIndex) * GetPukallCipherLevel(PukallCipherA) + GetPukallCipherCle(PukallCipherA, KeyIndex + 1))
    Private_PukallCipherCode(PukallCipherA)
    SetPukallCipherInter(PukallCipherA, GetPukallCipherInter(PukallCipherA) ! GetPukallCipherRes(PukallCipherA))
    KeyIndex + 2
    
  Next
  
  SetPukallCipherCounter(PukallCipherA, 0)
  
EndMacro

ProcedureDLL.s PukallCipherKeyGenerator(P_Length.w)
  
  For Index = 1 To P_Length
    
    Select Random(2)
        
      Case 0
        Min_ASCII.b = 48
        Max_ASCII.b = 57
        
      Case 1
        Min_ASCII = 97
        Max_ASCII = 122
        
      Case 2
        Min_ASCII = 65
        Max_ASCII = 90
        
    EndSelect
    
    Generated_Key.s = Generated_Key + Chr(Max_ASCII - Random(Max_ASCII - Min_ASCII))
    
  Next
  
  ProcedureReturn Generated_Key
EndProcedure

ProcedureDLL.s PukallCipherKeyGeneratorEx(P_Length.w)
  
  For Index = 1 To P_Length
    
    Select Random(6)
        
      Case 0
        Min_ASCII.b = 48
        Max_ASCII.b = 57
        
      Case 1
        Min_ASCII = 97
        Max_ASCII = 122
        
      Case 2
        Min_ASCII = 65
        Max_ASCII = 90
        
      Case 3
        Min_ASCII = 33
        Max_ASCII = 37
        
      Case 4
        Min_ASCII = 39
        Max_ASCII = 47
        
      Case 5
        Min_ASCII = 58
        Max_ASCII = 64
        
      Case 6
        Min_ASCII = 91
        Max_ASCII = 96
        
    EndSelect
    
    Generated_Key.s + Chr(Max_ASCII - Random(Max_ASCII - Min_ASCII))
    
  Next
  
  ProcedureReturn Generated_Key
EndProcedure 

ProcedureDLL.s PukallCipherNormalizedKey(P_Password.s, P_Level.w)
  
  NormalizedKey.s = MD5Fingerprint(@P_Password, Len(P_Password))
  
  Select P_Level
      
    Case #PUKALLCIPHER_LEVEL_GOOD ; 16 Characters
      NormalizedKey = Left(NormalizedKey, 16)
      
    Case #PUKALLCIPHER_LEVEL_HIGH ; 32 Characters
      NormalizedKey = NormalizedKey
      
    Case #PUKALLCIPHER_LEVEL_EXTREME ; 64 Characters
      NormalizedKey = NormalizedKey + MD5Fingerprint(@NormalizedKey, Len(NormalizedKey))
      
    Case #PUKALLCIPHER_LEVEL_INFERNAL ; 128 Characters
      For Index = 0 To 2
        NormalizedKey = NormalizedKey + MD5Fingerprint(@NormalizedKey, Len(NormalizedKey))
      Next
      
    Case #PUKALLCIPHER_LEVEL_INSANE ; 256 Characters
      For Index = 0 To 6
        NormalizedKey = NormalizedKey + MD5Fingerprint(@NormalizedKey, Len(NormalizedKey))
      Next
      
    Case #PUKALLCIPHER_LEVEL_RIDICULOUS ; 512 Characters
      For Index = 0 To 14
        NormalizedKey = NormalizedKey + MD5Fingerprint(@NormalizedKey, Len(NormalizedKey))
      Next
      
    Case #PUKALLCIPHER_LEVEL_LUDICROUS ; 1024 Characters
      For Index = 0 To 30
        NormalizedKey = NormalizedKey + MD5Fingerprint(@NormalizedKey, Len(NormalizedKey))
      Next
      
    Default ; #PUKALLCIPHER_LEVEL_GOOD ; 16 Characters
      NormalizedKey = Left(NormalizedKey, 16)
      
  EndSelect
  
  ProcedureReturn NormalizedKey
EndProcedure

ProcedureDLL.s PukallCipherEncrypt(P_Key.s, P_Buffer.s, P_Level.w) ; P_Key - 1024 Characters Max
  
  Select P_Level
      
    Case #PUKALLCIPHER_LEVEL_GOOD
      SetPukallCipherLevel(PukallCipher.PukallCipher, #PUKALLCIPHER_LEVEL_GOOD)
      SetPukallCipherX1A0Max(PukallCipher, 8)
      SetPukallCipherCleMax(PukallCipher, 16)
      
    Case #PUKALLCIPHER_LEVEL_HIGH
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_HIGH)
      SetPukallCipherX1A0Max(PukallCipher, 16)
      SetPukallCipherCleMax(PukallCipher, 32)
      
    Case #PUKALLCIPHER_LEVEL_EXTREME
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_EXTREME)
      SetPukallCipherX1A0Max(PukallCipher, 32)
      SetPukallCipherCleMax(PukallCipher, 64)
      
    Case #PUKALLCIPHER_LEVEL_INFERNAL
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_INFERNAL)
      SetPukallCipherX1A0Max(PukallCipher, 64)
      SetPukallCipherCleMax(PukallCipher, 128)
      
    Case #PUKALLCIPHER_LEVEL_INSANE
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_INSANE)
      SetPukallCipherX1A0Max(PukallCipher, 128)
      SetPukallCipherCleMax(PukallCipher, 256)
      
    Case #PUKALLCIPHER_LEVEL_RIDICULOUS
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_RIDICULOUS)
      SetPukallCipherX1A0Max(PukallCipher, 256)
      SetPukallCipherCleMax(PukallCipher, 512)
      
    Case #PUKALLCIPHER_LEVEL_LUDICROUS
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_LUDICROUS)
      SetPukallCipherX1A0Max(PukallCipher, 512)
      SetPukallCipherCleMax(PukallCipher, 1024)
      
    Default 
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_GOOD)
      SetPukallCipherX1A0Max(PukallCipher, 8)
      SetPukallCipherCleMax(PukallCipher, 16)
      
  EndSelect
  
  For KeyIndex = 0 To GetPukallCipherCleMax(PukallCipher) - 1
    SetPukallCipherCle(PukallCipher, KeyIndex, Asc(Mid(P_Key, KeyIndex + 1,1)))
  Next
  
  SetPukallCipherSi(PukallCipher, 0)
  SetPukallCipherX1A2(PukallCipher, 0)
  SetPukallCipherCounter(PukallCipher, 0)
  
  SetPukallCipherBufferLength(PukallCipher, Len(P_Buffer) - 1)
  
  For BufferIndex = 0 To GetPukallCipherBufferLength(PukallCipher)
    
    SetPukallCipherChar(PukallCipher, Asc(Mid(P_Buffer, BufferIndex + 1,1)))
    
    Private_PukallCipherAssemble(PukallCipher)
    
    SetPukallCipherCfc(PukallCipher, GetPukallCipherInter(PukallCipher) >> 8)
    SetPukallCipherCfd(PukallCipher, GetPukallCipherInter(PukallCipher) & 255)
    
    For KeyIndex = 0 To GetPukallCipherCleMax(PukallCipher) - 1
      SetPukallCipherCle(PukallCipher, KeyIndex, GetPukallCipherCle(PukallCipher, KeyIndex) ! GetPukallCipherChar(PukallCipher))
    Next
    
    SetPukallCipherChar(PukallCipher, GetPukallCipherChar(PukallCipher) ! (GetPukallCipherCfc(PukallCipher) ! GetPukallCipherCfd(PukallCipher)))
    SetPukallCipherDxx(PukallCipher, GetPukallCipherChar(PukallCipher) >> 4)
    SetPukallCipherExx(PukallCipher, GetPukallCipherChar(PukallCipher) & 15)
    CryptedBuffer.s + Chr($61 + GetPukallCipherDxx(PukallCipher))
    CryptedBuffer + Chr($61 + GetPukallCipherExx(PukallCipher))
    
  Next
  
  ResetPukallCipher(PukallCipher)
  
  ProcedureReturn CryptedBuffer
EndProcedure

ProcedureDLL.s PukallCipherDecrypt(P_Key.s, P_Buffer.s, P_Level.w) ; P_Key - 1024 Characters Max
  
  Select P_Level
      
    Case #PUKALLCIPHER_LEVEL_GOOD
      SetPukallCipherLevel(PukallCipher.PukallCipher, #PUKALLCIPHER_LEVEL_GOOD)
      SetPukallCipherX1A0Max(PukallCipher, 8)
      SetPukallCipherCleMax(PukallCipher, 16)
      
    Case #PUKALLCIPHER_LEVEL_HIGH
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_HIGH)
      SetPukallCipherX1A0Max(PukallCipher, 16)
      SetPukallCipherCleMax(PukallCipher, 32)
      
    Case #PUKALLCIPHER_LEVEL_EXTREME
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_EXTREME)
      SetPukallCipherX1A0Max(PukallCipher, 32)
      SetPukallCipherCleMax(PukallCipher, 64)
      
    Case #PUKALLCIPHER_LEVEL_INFERNAL
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_INFERNAL)
      SetPukallCipherX1A0Max(PukallCipher, 64)
      SetPukallCipherCleMax(PukallCipher, 128)
      
    Case #PUKALLCIPHER_LEVEL_INSANE
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_INSANE)
      SetPukallCipherX1A0Max(PukallCipher, 128)
      SetPukallCipherCleMax(PukallCipher, 256)
      
    Case #PUKALLCIPHER_LEVEL_RIDICULOUS
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_RIDICULOUS)
      SetPukallCipherX1A0Max(PukallCipher, 256)
      SetPukallCipherCleMax(PukallCipher, 512)
      
    Case #PUKALLCIPHER_LEVEL_LUDICROUS
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_LUDICROUS)
      SetPukallCipherX1A0Max(PukallCipher, 512)
      SetPukallCipherCleMax(PukallCipher, 1024)
      
    Default 
      SetPukallCipherLevel(PukallCipher, #PUKALLCIPHER_LEVEL_GOOD)
      SetPukallCipherX1A0Max(PukallCipher, 8)
      SetPukallCipherCleMax(PukallCipher, 16)
      
  EndSelect
  
  For KeyIndex = 0 To GetPukallCipherCleMax(PukallCipher) - 1
    SetPukallCipherCle(PukallCipher, KeyIndex, Asc(Mid(P_Key, KeyIndex + 1, 1)))
  Next
  
  SetPukallCipherSi(PukallCipher, 0)
  SetPukallCipherX1A2(PukallCipher, 0)
  SetPukallCipherCounter(PukallCipher, 0)
  
  SetPukallCipherBufferLength(PukallCipher, Len(P_Buffer) - 1)
  
  For BufferIndex = 0 To GetPukallCipherBufferLength(PukallCipher) Step 2
    
    SetPukallCipherRep(PukallCipher, Asc(Mid(P_Buffer, BufferIndex + 1, 1)))
    SetPukallCipherDxx(PukallCipher, GetPukallCipherRep(PukallCipher) - $61)
    SetPukallCipherDxx(PukallCipher, GetPukallCipherDxx(PukallCipher) << 4)
    
    SetPukallCipherRep(PukallCipher, Asc(Mid(P_Buffer, BufferIndex + 2, 1)))
    SetPukallCipherExx(PukallCipher, GetPukallCipherRep(PukallCipher) - $61)
    SetPukallCipherChar(PukallCipher, GetPukallCipherDxx(PukallCipher) + GetPukallCipherExx(PukallCipher))
    
    Private_PukallCipherAssemble(PukallCipher)
    
    SetPukallCipherCfc(PukallCipher, GetPukallCipherInter(PukallCipher) >> 8)
    SetPukallCipherCfd(PukallCipher, GetPukallCipherInter(PukallCipher) & 255)
    SetPukallCipherChar(PukallCipher, GetPukallCipherChar(PukallCipher) ! (GetPukallCipherCfc(PukallCipher) ! GetPukallCipherCfd(PukallCipher)))
    
    For KeyIndex = 0 To GetPukallCipherCleMax(PukallCipher) - 1
      SetPukallCipherCle(PukallCipher, KeyIndex, GetPukallCipherCle(PukallCipher, KeyIndex) ! GetPukallCipherChar(PukallCipher))
    Next
    
    DecryptedBuffer.s + Chr(GetPukallCipherChar(PukallCipher))
    
  Next 
  
  ResetPukallCipher(PukallCipher)
  
  ProcedureReturn DecryptedBuffer
EndProcedure

;/ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;/ <<<<< !!! WARNING - YOU ARE NOW IN A TESTING ZONE - WARNING !!! <<<<<
;/ <<<<< !!! WARNING - THIS CODE SHOULD BE COMMENTED - WARNING !!! <<<<<
;/ <<<<< !!! WARNING - BEFORE THE FINAL COMPILATION. - WARNING !!! <<<<<
;/ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Dim Text00.s(4)
Dim Text01.s(4)

Text00(0) = "PureBasic it's the best progamming language in the galaxy !"
Text00(1) = "Potatoes, Tomatoes, Carrots, Cumcumber, Pepper, Basilic, ..."
Text00(2) = "Apple, Bananas, Pineapple, Orange, Citrus, Lime, Strawberry, ..."
Text00(3) = "PukallCipher algorythm, Security Level max : 8192 Bits"
Text00(4) = "My girlfriend is more than a simple woman, She is a goddess !"

Password.s = "dwm0bdd317"
SecurityLevel.l = #PUKALLCIPHER_LEVEL_GOOD
KeyLength.w = 16

For Index = 0 To 6
  
  Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
  Debug "; Security Level : " + Str(SecurityLevel)
  Debug "; Key Length : " + Str(KeyLength)
  Debug "; Password : " + Password
  Debug ""
  
  For TextID = 0 To 4
    
    MyKey.s = PukallCipherNormalizedKey(Password, SecurityLevel)
    EncryptedString.s = PukallCipherEncrypt(MyKey, Text00(TextID), SecurityLevel)
    DecryptedString.s = PukallCipherDecrypt(MyKey, EncryptedString, SecurityLevel)
    
    Debug "The Key : " + MyKey
    Debug "Orginal String : " + Text00(TextID)  
    Debug "Encrypted String : " + EncryptedString
    Debug "Decrypted String : " + DecryptedString
    Debug ""
    
  Next
  
  KeyLength << 1
  SecurityLevel << 1
  
Next

Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; Test Read and Write on file"
Debug "" 

If CreateFile(0, "FileTest.dat")
  
  MyKey.s = PukallCipherNormalizedKey(Password, SecurityLevel)
  CryptedKey.s = PukallCipherEncrypt(MyKey, MyKey, SecurityLevel)
  WriteStringN(0, CryptedKey)
  
  For TextID = 0 To 4
    EncryptedString.s = PukallCipherEncrypt(MyKey, Text00(TextID), SecurityLevel)
    WriteStringN(0, EncryptedString)
  Next
  
  CloseFile(0)
  
EndIf

If ReadFile(1, "FileTest.dat")
  
  MyKey.s = PukallCipherNormalizedKey(Password, SecurityLevel)
  CryptedKey.s = ReadString(1)
  DecryptedKey.s = PukallCipherDecrypt(MyKey, CryptedKey, SecurityLevel)
  
  If MyKey = DecryptedKey
    
    For TextID = 0 To 4
      EncryptedString.s = ReadString(1)
      Text01(TextID) = PukallCipherDecrypt(MyKey, EncryptedString, SecurityLevel)
      Debug Text01(TextID)
    Next
    
  Else 
    
    Debug "Incorrect Password !"
    
  EndIf
  
  CloseFile(1) 
  
EndIf

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

Posted: Fri Jun 12, 2009 5:29 am
by +18
Hello Guimauve
please a sample here :D
THX

Posted: Fri Jun 12, 2009 9:25 am
by DoubleDutch
Guimauve: Thanks - this should be built-in to PB. :)

Here is an FAQ on this:
http://membres.lycos.fr/pc1/pc1.html

Looks pretty good.

Posted: Fri Jun 12, 2009 1:41 pm
by SFSxOI
Looks interesting. Sample usage please ?

Example

Posted: Sat Jun 13, 2009 4:06 am
by electrochrisso
Nice Code :D

A simple example

Code: Select all

XIncludeFile "PukallCipher.pbi"

a$="The quick brown fox jumped over the lazy dogs back"
b$=PukallCipherEncrypt("Password", a$, P_Level.l = #PUKALLCIPHER_LEVEL_GOOD)
Debug b$
a$=PukallCipherDecrypt("Password", b$, P_Level.l = #PUKALLCIPHER_LEVEL_GOOD)
Debug a$

Posted: Sun Jun 14, 2009 5:15 pm
by netmaestro
I'm not convinced this is very strong, as the encrypted text always contains only the ascii characters from 97-122.

Posted: Tue Jun 16, 2009 12:09 am
by Guimauve
I have updated the lib (Now security level reach 8192 Bits and KeyGenerator function added) See the first post.

Best Regards

Guimauve

Posted: Tue Jun 16, 2009 12:36 am
by DoubleDutch
Thanks for the update. :)

Posted: Sun Aug 30, 2009 6:31 pm
by Guimauve
Another Update...

Private_PukallCipherCode(PukallCipherA) --> change from Procedure to Macro (Speed Optimisation)
Private_PukallCipherAssemble(PukallCipherA) --> change from Procedure to Macro (Speed Optimisation)
PukallCipherNormalizedKey(P_Password.s, P_Level.w) --> Procedure added.

Best Regards
Guimauve