Page 1 sur 1

PC1 CIPHER With 128-bit keys

Publié : dim. 08/févr./2009 20:21
par zaphod
Salut à tous,

J'ai fait un portage en pure basic du cryptage symétrique PC1.
La clé de codage est limitée à 16 caractères (128 bits).
Si ça peut servir à quelqu'un...

Code : Tout sélectionner

;// PC1 CIPHER With 128-bit keys //
;// (c) Alexander PUKALL 1991 //
;//  Freeware. Can be freely use even For commercial purposes //
;// Pure Basic portage © 2009 by Z@ph0d  
;// http://landzone.free.fr
;// 

EnableExplicit
Global ax.l,bx.l,cx.l,dx.l,si.l,x1a2.l,res.l,i.l,inter.l
Global	Dim x1a0.l(7)
Global Dim	cle.c(16)
;
Procedure code()
  dx= x1a2+i
	ax= x1a0(i)
  cx= $015a
  bx= $4e35
  Swap ax,si
  Swap ax,dx
	If ax <> 0 
  ax*bx
  EndIf
  Swap ax,cx
  If ax <> 0 
    ax*si
    cx+ax
  EndIf
	Swap ax,si
	ax+bx
	dx+cx
	ax+1
  x1a2= dx
	x1a0(i)= ax
  res= ax ! dx
	i+1
EndProcedure

Procedure Assemble()
	x1a0(0)= ( cle(0)*256 ) + cle(1)
  code()
  inter= res

	x1a0(1)= x1a0(0) ! ( (cle(2)*256) + cle(3) )
	code()
	inter= inter ! res

	x1a0(2)= x1a0(1) ! ( (cle(4)*256) + cle(5) )
	code()
	inter= inter ! res;

	x1a0(3)= x1a0(2) ! ( (cle(6)*256) + cle(7) )
	code()
	inter= inter ! res

	x1a0(4)= x1a0(3) ! ( (cle(8)*256) + cle(9) )
	code()
	inter= inter ! res

  x1a0(5)= x1a0(4) ! ( (cle(10)*256) + cle(11) )
  code()
  inter= inter ! res

  x1a0(6)= x1a0(5) ! ( (cle(12)*256) + cle(13) )
  code()
  inter= inter ! res

  x1a0(7)= x1a0(6) ! ( (cle(14)*256) + cle(15) )
  code()
  inter= inter ! res
	i= 0
EndProcedure

Procedure.s Crypt(key.s, Buffer.s)
; ThisCle contains the password, 16 characters at max.
Protected 	Rep.c, c.c, d.c, e.c, bl.l,cr.s,compte.l,j.l,cfc.l,cfd.l
	;
	ZeroMemory_(@Cle(), ArraySize(Cle()))
	;
	For compte=0 To Len(key)-1
	cle(compte)=Asc(Mid(key,compte+1,1))
	Next compte
	;
	si=0
	x1a2=0
	i=0
  bl=Len(buffer)
  ;
	For j=0 To bl-1 
		c= Asc(Mid(Buffer,j+1,1))   
		Assemble()
		cfc= inter >> 8
		cfd= inter & 255
		For compte= 0 To 15 
		 cle(compte)= cle(compte) ! c
		Next compte
		c= c ! (cfc ! cfd)

		d= c >> 4 
		e= c & 15
		;
    cr+Chr($61+d)
		cr+Chr($61+e)
		;
	Next j
	ProcedureReturn cr
EndProcedure

Procedure.s Decrypt(key.s, Buffer.s)
Protected 	Rep.c, c.c, d.c, e.c,bl.l,de.s,compte.l,j.l,cfc.l,cfd.l

	ZeroMemory_(@Cle(), ArraySize(Cle()))
	;
	For compte=0 To Len(key)-1
	cle(compte)=Asc(Mid(key,compte+1,1))
	Next compte
	;
	si=0
	x1a2=0
	i=0
  bl=Len(buffer)
	;
	For j=0 To bl-1 Step 2 
          rep= Asc(Mid(Buffer,j+1,1))
          d=rep-$61  
          d= d << 4
          ;
          rep= Asc(Mid(Buffer,j+2,1)) 
          e=rep-$61
          c= d + e
          ;
          Assemble()
          cfc= inter >> 8
          cfd= inter & 255
          ;
          c= c ! (cfc ! cfd)
          ;
          For compte= 0 To 15 
            cle(compte)= cle(compte) ! c
          Next compte
          ;
          de+Chr(c)
  Next j 
ProcedureReturn de
EndProcedure


Define v1.s,v2.s
v1=crypt("PassWord","Ceci est un essai...")
Debug v1

v2=decrypt("PassWord",v1)
Debug v2

Z@ph0d

Publié : dim. 08/févr./2009 21:20
par Ar-S
Merci pour ce partage

Publié : dim. 08/févr./2009 21:37
par Kwai chang caine
Je ne connais pas les diverses methodes de cryptages qui ont un nom. :oops:
C'est interessant, merci pour ce partage 8)

Publié : mar. 30/juin/2009 10:28
par Guimauve
Bonjour à tous,

Voici ma version de cet algorithme de cryptage. Juste pour m'amuser un peu, le niveau de cryptage atteint 8192 Bits (Avec un bon mot de passe ça devrait prendre plusieurs milliards d'année pour passer à travers). J'ai également ajouté deux commandes pour générer des clés de cryptage complexes.

A+
Guimauve

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Pukall Cipher algorithm
; File : PukallCiper.pb
; File Version : 1.0.0
; Programmation : OK
; Programmed by : Guimauve
; Date : 13-06-2009
; Last Update : 13-06-2009
; Coded for PureBasic V4.31
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

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

Procedure Private_PukallCipherAssemble(*PukallCipherA.PukallCipher)
  
  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)
  
EndProcedure

ProcedureDLL.s PukallCipherKeyGenerator(P_Level.w)
  
  Select P_Level
      
    Case #PUKALLCIPHER_LEVEL_GOOD 
      P_Length.w = 16
      
    Case #PUKALLCIPHER_LEVEL_HIGH 
      P_Length = 32
      
    Case #PUKALLCIPHER_LEVEL_EXTREME 
      P_Length = 64
      
    Case #PUKALLCIPHER_LEVEL_INFERNAL 
      P_Length = 128
      
    Case #PUKALLCIPHER_LEVEL_INSANE 
      P_Length = 256
      
    Case #PUKALLCIPHER_LEVEL_RIDICULOUS 
      P_Length = 512
      
    Case #PUKALLCIPHER_LEVEL_LUDICROUS 
      P_Length = 1024
      
    Default 
      P_Length = 16
      
  EndSelect
  
  For Index = 1 To P_Length
    
    Select Random(2)
        
      Case 0
        Min_ASCII.w = 48
        Max_ASCII.w = 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_Level.w)
  
  Select P_Level
      
    Case #PUKALLCIPHER_LEVEL_GOOD 
      P_Length.w = 16
      
    Case #PUKALLCIPHER_LEVEL_HIGH 
      P_Length = 32
      
    Case #PUKALLCIPHER_LEVEL_EXTREME 
      P_Length = 64
      
    Case #PUKALLCIPHER_LEVEL_INFERNAL 
      P_Length = 128
      
    Case #PUKALLCIPHER_LEVEL_INSANE 
      P_Length = 256
      
    Case #PUKALLCIPHER_LEVEL_RIDICULOUS 
      P_Length = 512
      
    Case #PUKALLCIPHER_LEVEL_LUDICROUS 
      P_Length = 1024
      
    Default 
      P_Length = 16
      
  EndSelect
  
  For Index = 1 To P_Length
    
    Select Random(6)
        
      Case 0
        Min_ASCII.w = 48
        Max_ASCII.w = 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 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 Text.s(4)

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

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 ""
  
  For TextID = 0 To 4
    
    MyKey.s = PukallCipherKeyGenerator(SecurityLevel)
    EncryptedString.s = PukallCipherEncrypt(MyKey, Text(TextID), SecurityLevel)
    DecryptedString.s = PukallCipherDecrypt(MyKey, EncryptedString, SecurityLevel)
    
    Debug "The Key : " + MyKey
    Debug "Orginal String : " + Text(TextID)  
    Debug "Encrypted String : " + EncryptedString
    Debug "Decrypted String : " + DecryptedString
    Debug ""
    
  Next
   
  KeyLength << 1
  SecurityLevel << 1
  
Next

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

Publié : mer. 01/juil./2009 12:15
par Ar-S
c'est l'etat qui va pas être content :D

Publié : dim. 30/août/2009 19:16
par Guimauve
Une petite mise à jour...

Une petite optimisation + Ajout une nouvelle fonction

A+
Guimauve

Code : Tout sélectionner

; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; 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 "Wrong Password"
    
  EndIf
  
  CloseFile(1) 
  
EndIf

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

Publié : lun. 31/août/2009 10:35
par Kwai chang caine
Ar-S a écrit :c'est l'etat qui va pas être content :D
:lol: Tu m'étonne :lol:
Remarque ils ont des super endroits climatisés ou on a tout son temps pour faire de la prog :roll:
On les appel les "club merde" :lol:

Merci beaucoup GUIMAUVE pour ce partage 8)

Publié : lun. 31/août/2009 11:12
par kernadec
bonjour zaphod & Guimauve

merci, pour les deux codes, super sympa

cordialement